Pytest plugin to restrict the test types allowed
Project description
Pytest plugin to restrict the test types allowed.
Testing a Django project? Check out my book Speed Up Your Django Tests which covers loads of ways to write faster, more accurate tests.
Features
This plugin allows you to restrict the test types allowed to ensure they inherit from one of a given list of classes. Useful on projects where you have custom test classes that developers may forget about.
Installation
Install with:
python -m pip install pytest-restrict
Python 3.9 to 3.13 supported.
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 allowed test base classes. The import paths are passed to pkgutil.resolve_name(), for which you should prefer the form <module.path>:<classname>. It’s best to set --restrict-types within addopts in your pytest configuration file.
For example, to restrict tests to Django’s test case classes within pytest.ini:
[pytest]
addopts = --restrict-types django.test:SimpleTestCase
To allow function tests and other non-class test types (such as doctests), provide the special string “None”:
[pytest]
addopts = --restrict-types None,django.test:SimpleTestCase
History
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 error if it encountered non-whitelisted test types.
This package is a pytest port of that plugin.
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
File details
Details for the file pytest_restrict-4.7.0.tar.gz
.
File metadata
- Download URL: pytest_restrict-4.7.0.tar.gz
- Upload date:
- Size: 5.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 98c7fc20dedb47ba2dee0d98fe7834f6fcbd923a58b0b54b2cdf3eda5979fb56 |
|
MD5 | d238681386634db38f1a50d804a3637c |
|
BLAKE2b-256 | 1cdb50dd4e5351ba5bb4c374a0b0519bac7979037c9ffa1b03c16502ab27a0ff |
File details
Details for the file pytest_restrict-4.7.0-py3-none-any.whl
.
File metadata
- Download URL: pytest_restrict-4.7.0-py3-none-any.whl
- Upload date:
- Size: 4.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 32a2b0ceef7e70938100843ebb9ed7bec46b2d279869267ca1adc77979ba0403 |
|
MD5 | eda0b3d90b51d04c51e9c9ad88a9992d |
|
BLAKE2b-256 | db42d3b82f358d297a653d51f30fdfcb19470698630c92dfa4c2b1699a1a246b |