Unit test
Pytest
Unittest Python native module
https://docs.python.org/3/library/unittest.mock.html
very useful because you can easily replace the module call within the test target
e.g. you can pretend a module/methods return value within the test target, without the need to modify it.
Setup
- Better to start with this structure. A separated test folders
- ~~Create an empty
__init__.py
inproj_root/tests/
~~- ~~Now you can run pytest and import the src files correctly~~
- ~~BUT, the
import
inside src files, that you imported, still not work.~~
-
Create a file
[conftest.py](http://conftest.py)
inproj_root/tests/
with below content:import os import sys sys.path.append( os.path.abspath(os.path.dirname(os.path.abspath(__file__)) + "/../src/") )
So the src folder is also added to sys path