Pytest plugin to restrict the test types allowed
Project description
Pytest plugin to restrict the test types allowed.
Features
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.
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.
Installation
Install from pip with:
python -m pip install pytest-restrict
Python 3.6 to 3.10 supported.
Testing a Django project? Check out my book Speed Up Your Django Tests which covers loads of best practices so you can write faster, more accurate tests.
Usage
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
This is most useful as a default set with addopts in your pytest.ini (docs):
[pytest]
addopts = --restrict-types django.test.TestCase,django.test.SimpleTestCase
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for pytest_restrict-4.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0fe852ced2ee2d84ea3f4641ab0900a423d2314b5972711b2db732ba1bfb227a |
|
MD5 | 0311070f242b607b09d010818ee76673 |
|
BLAKE2b-256 | 8d573a78df11f23295c4dd1e70dbc27336b291b4929202a97b66d736441172d8 |