Unitary tests#

Develop unitary tests to validated all functions and methods by using the pytest framework.

Python package organisation#

p400-xxx/
    p400xxx/
    tests/
        __init__.py
        conftest.py
        test_100_myclass1.py
        test_200_myclass2.py

File naming convention#

Naming convention for test files is given in the table below. Values between {} are mandatory while those between [] are optional.

grammar

definition

exemple

test_{section id}_{class name}.csv

unique file name

test_300_ltm4677.py

{section id}

identifier of the section

100, 200, …

{class name}

name of the class in lowercase

ltm4677

Test function naming convention#

Naming convention for test function is given in the table below. Values between {} are mandatory while those between [] are optional.

grammar

definition

exemple

test_{class name}_{method}_{test id}.csv

unique name

test_ltm4677_read_cfg_from_file_330

{class name}

name of the class in lower case

ltm4677

{method}

name of the method in lowercase

read_cfg_from_file

{test id}

unique 3 digit number to identify the test. the MSB is the one of the section id

330

Import a class or function in a test module#

    from p400xxx.mymodule import myclass, myfunction

Run the test suite#

    (venv) $ cd p400-xxx/tests
    (venv) $ pytest --collect-only -q   # (list of availble test)
    (venv) $ pytest -k test_id          # (run one test identified by its number)        
    (venv) $ pytest                     # (run all tests)