FORK
Published

Fork+PyTest

Install forkapi Python package

BeginnerProtip2 hours263
Fork+PyTest

Things used in this project

Hardware components

FORK
×1

Story

Read more

Schematics

shema

Code

Code snippet #11

Plain text
    ‘conftest.py’:
        # -*- coding: utf-8 -*-
        from forkapi import fork
        import pytest
            def pytest_addoption(parser):
            """Adding extra options to INI file"""
                parser.addini('fork', help='FORK IP address')
    

Code snippet #12

Plain text
    ‘conftest.py’:
        # -*- coding: utf-8 -*-
        from forkapi import fork
        import pytest
            def pytest_addoption(parser):
            """Adding extra options to INI file"""
                parser.addini('fork', help='FORK IP address')
    

Code snippet #13

Plain text
    ...

        @pytest.fixture(scope='session')
        def stand(pytestconfig):
        
            stand_ip = pytestconfig.getini('fork')
            
            f = fork.Fork(stand_ip)
            f.connect()
            
            return f
    

Code snippet #14

Plain text
    ...

        @pytest.fixture(scope='session')
        def stand(pytestconfig):
        
            stand_ip = pytestconfig.getini('fork')
            
            f = fork.Fork(stand_ip)
            f.connect()
            
            return f
    

Code snippet #15

Plain text
    ‘pytest.ini’:
        [pytest]
        fork = 192.168.0.109
    

Code snippet #16

Plain text
    ‘pytest.ini’:
        [pytest]
        fork = 192.168.0.109
    

Code snippet #19

Plain text
    addr = 0x4
    data = b'\xE3
    res = dev1.I2CWriteRead(addr,3,data)
    

Code snippet #20

Plain text
    addr = 0x4
    data = b'\xE3
    res = dev1.I2CWriteRead(addr,3,data)
    

Code snippet #23

Plain text
    ‘test_foo.py’:
        # run this test the first
        @pytest.mark.run(order=1)
        def test_voltage2(stand):
            """Yet another voltage Test"""
                limit_min = 2
                limit_max = 4
                # measure voltage at AI2
                measured = stand.aiGet(2)
                # compare measured value with the limits
                assert limit_min <= measured <= limit_max
    

Code snippet #24

Plain text
    ‘test_foo.py’:
        # run this test the first
        @pytest.mark.run(order=1)
        def test_voltage2(stand):
            """Yet another voltage Test"""
                limit_min = 2
                limit_max = 4
                # measure voltage at AI2
                measured = stand.aiGet(2)
                # compare measured value with the limits
                assert limit_min <= measured <= limit_max
    

Code snippet #3

Plain text
    ‘test_foo.py’:
         # -*- coding: utf-8 -*-
         from forkapi import fork
         def test_voltage0():
             """Voltage Test"""
                limit_min = 3.0
                limit_max = 3.6
                # initialize Fork instance
                f = fork.Fork('192.168.0.109')
                # measure voltage at AI0
                measured = f.aiGet(0)
                # compare measured value with the limits
                # assert raises an AssertionError in case if the expression returns False
                assert limit_min <= measured <= limit_max
    

Code snippet #4

Plain text
    ‘test_foo.py’:
         # -*- coding: utf-8 -*-
         from forkapi import fork
         def test_voltage0():
             """Voltage Test"""
                limit_min = 3.0
                limit_max = 3.6
                # initialize Fork instance
                f = fork.Fork('192.168.0.109')
                # measure voltage at AI0
                measured = f.aiGet(0)
                # compare measured value with the limits
                # assert raises an AssertionError in case if the expression returns False
                assert limit_min <= measured <= limit_max
    

Code snippet #5

Plain text
    ‘test_foo.py’ (continued):
    
        def test_voltage1():
        
            """Another voltage Test"""
            
                limit_min = -3.6
                limit_max = -3.3
                
                f = fork.Fork('192.168.0.109')
                
                # measure voltage at AI1
                measured = f.aiGet(1)
                
                # compare measured value with the limits
                assert limit_min <= measured <= limit_max
            
        def test_voltage2():
        
            """Yet another voltage Test"""
            
                limit_min = 2
                limit_max = 4
                
                f = fork.Fork('192.168.0.109')
                
                # measure voltage at AI2
                measured = f.aiGet(2)
                
                # compare measured value with the limits
                assert limit_min <= measured <= limit_max
    

Code snippet #6

Plain text
    ‘test_foo.py’ (continued):
    
        def test_voltage1():
        
            """Another voltage Test"""
            
                limit_min = -3.6
                limit_max = -3.3
                
                f = fork.Fork('192.168.0.109')
                
                # measure voltage at AI1
                measured = f.aiGet(1)
                
                # compare measured value with the limits
                assert limit_min <= measured <= limit_max
            
        def test_voltage2():
        
            """Yet another voltage Test"""
            
                limit_min = 2
                limit_max = 4
                
                f = fork.Fork('192.168.0.109')
                
                # measure voltage at AI2
                measured = f.aiGet(2)
                
                # compare measured value with the limits
                assert limit_min <= measured <= limit_max
    

Code snippet #7

Plain text
    ‘conftest.py’:
    # -*- coding: utf-8 -*-
    from forkapi import fork
    import pytest
    @pytest.fixture(scope='session')
    def stand():
        stand_ip = '192.168.0.109'
        f = fork.Fork(stand_ip)
        f.connect()
        return f
    

Code snippet #8

Plain text
    ‘conftest.py’:
    # -*- coding: utf-8 -*-
    from forkapi import fork
    import pytest
    @pytest.fixture(scope='session')
    def stand():
        stand_ip = '192.168.0.109'
        f = fork.Fork(stand_ip)
        f.connect()
        return f
    

Code snippet #9

Plain text
    ‘test_foo.py’:
        # -*- coding: utf-8 -*-
        # from forkapi import fork
        def test_voltage0(stand):
            """Voltage Test"""
                limit_min = 3.0
                limit_max = 3.6
                measured = stand.aiGet(0)
                assert limit_min <= measured <= limit_ma
    

Code snippet #10

Plain text
    ‘test_foo.py’:
        # -*- coding: utf-8 -*-
        # from forkapi import fork
        def test_voltage0(stand):
            """Voltage Test"""
                limit_min = 3.0
                limit_max = 3.6
                measured = stand.aiGet(0)
                assert limit_min <= measured <= limit_ma
    

Github

https://github.com/pytest-dev/pytest

Credits

FORK
11 projects • 1 follower
FORK for test-engineers to automate fixtures. Just take Fork, PyTest and program the tests in Python. The test stand is ready!
Contact

Comments

Please log in or sign up to comment.