Skip to main content

pytest-restrict

https://img.shields.io/travis/adamchainz/pytest-restrict.svg https://img.shields.io/pypi/v/pytest-restrict.svg https://img.shields.io/badge/code%20style-black-000000.svg

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:

pip install pytest-restrict

Python 3.5 to 3.8 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 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

History

3.1.0 (2019-12-19)

  • 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).

3.0.0 (2018-02-28)

  • Drop Python 2 support, only Python 3.4+ is supported now.

2.0.0 (2016-04-29)

  • 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.

1.0.0 (2016-04-17)

  • First release on PyPI

Metadata

Release files for pytest-restrict 3.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pytest-restrict 3.1.0
File Size Uploaded
pytest-restrict-3.1.0.tar.gz 5.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pytest-restrict 3.1.0
File Interpreter ABI Platform
pytest_restrict-3.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 10.1 kB

Release files / pytest-restrict-3.1.0.tar.gz

Download URL pytest-restrict-3.1.0.tar.gz
Size 5.4 kB
Tags Source
SHA-256 checksum
How to use checksums
6cf1b7f9cf0ad79c0a1167b2f77acbe0ff897b01ef63f680bf13145c4ea9ae08
BLAKE2b-256 checksum
How to use checksums
0496251518512779271bc7456779d776d40026e138e65fbb02e570fe4542f233
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.38.0 CPython/3.7.5

Release files / pytest_restrict-3.1.0-py3-none-any.whl

Download URL pytest_restrict-3.1.0-py3-none-any.whl
Size 4.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d34587de16dbf36bbd6751b5c84fd16308d87de4332f03c8c3cff137cde7a574
BLAKE2b-256 checksum
How to use checksums
9831394e33a699310e45ddd0fbc488990644710052b7fcec06cdccf6e235cdfc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.38.0 CPython/3.7.5

Release history Release notifications | RSS feed

4.9.0

2 release files

4.8.0

2 release files

4.7.0

2 release files

4.6.0

2 release files

4.5.0

2 release files

4.4.0

2 release files

4.3.0

2 release files

4.2.0

2 release files

4.1.0

2 release files

4.0.0

2 release files

This release

3.1.0 This release

2 release files

3.0.0

2 release files

2.0.0

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page