PytestSetting Project Test System: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
Line 11: Line 11:
               └─ test_my_function.py
               └─ test_my_function.py
<font size=-1>
<font size=-1>
=Environment=
Add the path to the directory that contains the module to test (in this case ./src/main/python contains my_module_to_test.py):
<syntaxhighlight lang='bash'>
PYTHONPATH="$(dirname $0)/src/main/python"
export PYTHONPATH
</syntaxhighlight>


=Structure of a Test File=
=Structure of a Test File=

Revision as of 01:15, 9 June 2022

Internal

Layout

...
 └─ test
     └─ python
         └─ my_module
             ├─ data
             └─ test_my_function.py

Environment

Add the path to the directory that contains the module to test (in this case ./src/main/python contains my_module_to_test.py):

PYTHONPATH="$(dirname $0)/src/main/python"
export PYTHONPATH

Structure of a Test File

import pytest
from pathlib import Path
from my_module_to_test import some_function

def get_data_file(file_name):
    return Path(Path(__file__).parent, f'./data/{file_name}')