PyTests¶
Directory¶
The tests folder should mirror src to ensure that each submodule is properly tested. Include an integration folder under tests to evaluate larger tests.
project
└───src
| └─── __init__.py
│ └─── ModuleA
│ └─── __init__.py
│ └─── A.py
└───tests
└─── __init__.py
└─── ModuleA
└─── __init__.py
└─── A_test.py
Warning
It is generally recommended that you do not have tests in your src folder since they would become importable as part of your distribution.
Tip
Tests should include both unit and integration testing.
Info
PyTest provides additional features such as parameter sweeping, fixtures, and logging. These should be applied depending on the test requirements.
Coverage¶
PyTests offers coverage support. When running PyTests with Coverage, it will generate a HTML that show which parts of your repo have not been traced using PyTests. This lets you know which areas of your code still need to be tested.
Allure¶
Allure provides a dashboard that aggregates your pytest results. Allure provides additional functionality like tagging for your tests to organize them into a tree structure. In order to use allure, you must install it via Homebrew:
To create and view an Allure report: