Pytest plugin to restrict the test types allowed
Pytest plugin to restrict the test types allowed.
This plugin allows you to restrict the test types allowed to ensure they inherit from one of a given list of classes. You might need this on large projects where you have custom test classes that developers might forget about.
I developed this feature in a closed source Nose plugin whilst working on the big Django project at YPlan. We had some custom enhancements and fixes on top of the Django test classes, but developers sometimes forgot about using them and instead used the built-in unittest classes, or the plain Django ones. Our solution was to just make the test runner blow up if it encountered non-whitelisted test types. This is a Pytest port of that plugin.
Install from pip with:
pip install pytest-restrict
Python 3.5 to 3.8 supported.
Pytest will automatically find the plugin and use it when you run pytest, however by default there are no restrictions. To restrict the test types, provide --restrict-types as a comma-separated list of import paths to allowable test case base classes, for example:
# Allow only test cases that inherit from Django pytest --restrict-types django.test.TestCase,django.test.SimpleTestCase
If you wish to allow function tests and other non-class test types (e.g. doctests), provide the special string ‘None’, for example:
# Allow function tests and our custom tests pytest --restrict-types None,myproject.test.TestCase
- Update Python support to 3.5-3.8, as 3.4 has reached its end of life.
- Converted setuptools metadata to configuration file. This meant removing the __version__ attribute from the package. If you want to inspect the installed version, use importlib.metadata.version("pytest-restrict") (docs / backport).
- Drop Python 2 support, only Python 3.4+ is supported now.
- Changed the format of --restrict-types to take a comma-separated list of import paths rather than space separated, which fixes the parsing of e.g. py.test --restrict-types my.TestCase run/these/test_files.py.
- First release on PyPI
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
|Filename, size||File type||Python version||Upload date||Hashes|
|Filename, size pytest_restrict-3.1.0-py3-none-any.whl (4.7 kB)||File type Wheel||Python version py3||Upload date||Hashes View|
|Filename, size pytest-restrict-3.1.0.tar.gz (5.4 kB)||File type Source||Python version None||Upload date||Hashes View|
Hashes for pytest_restrict-3.1.0-py3-none-any.whl