Name | pytest-restrict JSON |
Version |
4.7.0
JSON |
| download |
home_page | None |
Summary | Pytest plugin to restrict the test types allowed |
upload_time | 2024-10-24 09:16:57 |
maintainer | None |
docs_url | None |
author | None |
requires_python | >=3.9 |
license | None |
keywords |
class
pytest
restrict
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
===============
pytest-restrict
===============
.. image:: https://img.shields.io/github/actions/workflow/status/adamchainz/pytest-restrict/main.yml.svg?branch=main&style=for-the-badge
:target: https://github.com/adamchainz/pytest-restrict/actions?workflow=CI
.. image:: https://img.shields.io/badge/Coverage-100%25-success?style=for-the-badge
:target: https://github.com/adamchainz/pygments-git/actions?workflow=CI
.. image:: https://img.shields.io/pypi/v/pytest-restrict.svg?style=for-the-badge
:target: https://pypi.org/project/pytest-restrict/
.. image:: https://img.shields.io/badge/code%20style-black-000000.svg?style=for-the-badge
:target: https://github.com/psf/black
.. image:: https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=white&style=for-the-badge
:target: https://github.com/pre-commit/pre-commit
:alt: pre-commit
Pytest plugin to restrict the test types allowed.
----
**Testing a Django project?**
Check out my book `Speed Up Your Django Tests <https://adamchainz.gumroad.com/l/suydt>`__ 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:
.. code-block:: bash
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.
.. |addopts| replace:: ``addopts``
__ https://docs.pytest.org/en/latest/reference/reference.html#confval-addopts
For example, to restrict tests to Django’s `test case classes <https://docs.djangoproject.com/en/stable/topics/testing/tools/#provided-test-case-classes>`__ within ``pytest.ini``:
.. |pkgutil.resolve_name()| replace:: ``pkgutil.resolve_name()``
__ https://docs.python.org/3/library/pkgutil.html#pkgutil.resolve_name
.. code-block:: 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”:
.. code-block:: ini
[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.
Raw data
{
"_id": null,
"home_page": null,
"name": "pytest-restrict",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.9",
"maintainer_email": null,
"keywords": "class, pytest, restrict",
"author": null,
"author_email": "Adam Johnson <me@adamj.eu>",
"download_url": "https://files.pythonhosted.org/packages/1c/db/50dd4e5351ba5bb4c374a0b0519bac7979037c9ffa1b03c16502ab27a0ff/pytest_restrict-4.7.0.tar.gz",
"platform": null,
"description": "===============\npytest-restrict\n===============\n\n.. image:: https://img.shields.io/github/actions/workflow/status/adamchainz/pytest-restrict/main.yml.svg?branch=main&style=for-the-badge\n :target: https://github.com/adamchainz/pytest-restrict/actions?workflow=CI\n\n.. image:: https://img.shields.io/badge/Coverage-100%25-success?style=for-the-badge\n :target: https://github.com/adamchainz/pygments-git/actions?workflow=CI\n\n.. image:: https://img.shields.io/pypi/v/pytest-restrict.svg?style=for-the-badge\n :target: https://pypi.org/project/pytest-restrict/\n\n.. image:: https://img.shields.io/badge/code%20style-black-000000.svg?style=for-the-badge\n :target: https://github.com/psf/black\n\n.. image:: https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=white&style=for-the-badge\n :target: https://github.com/pre-commit/pre-commit\n :alt: pre-commit\n\nPytest plugin to restrict the test types allowed.\n\n----\n\n**Testing a Django project?**\nCheck out my book `Speed Up Your Django Tests <https://adamchainz.gumroad.com/l/suydt>`__ which covers loads of ways to write faster, more accurate tests.\n\n----\n\nFeatures\n========\n\nThis plugin allows you to restrict the test types allowed to ensure they inherit from one of a given list of classes.\nUseful on projects where you have custom test classes that developers may forget about.\n\nInstallation\n============\n\nInstall with:\n\n.. code-block:: bash\n\n python -m pip install pytest-restrict\n\nPython 3.9 to 3.13 supported.\n\nUsage\n=====\n\nPytest will automatically find the plugin and use it when you run ``pytest``, however by default there are no restrictions.\nTo restrict the test types, provide ``--restrict-types`` as a comma-separated list of import paths to allowed test base classes.\nThe import paths are passed to |pkgutil.resolve_name()|__, for which you should prefer the form ``<module.path>:<classname>``.\nIt\u2019s best to set ``--restrict-types`` within |addopts|__ in your pytest configuration file.\n\n.. |addopts| replace:: ``addopts``\n__ https://docs.pytest.org/en/latest/reference/reference.html#confval-addopts\n\nFor example, to restrict tests to Django\u2019s `test case classes <https://docs.djangoproject.com/en/stable/topics/testing/tools/#provided-test-case-classes>`__ within ``pytest.ini``:\n\n.. |pkgutil.resolve_name()| replace:: ``pkgutil.resolve_name()``\n__ https://docs.python.org/3/library/pkgutil.html#pkgutil.resolve_name\n\n.. code-block:: ini\n\n [pytest]\n addopts = --restrict-types django.test:SimpleTestCase\n\nTo allow function tests and other non-class test types (such as doctests), provide the special string \u201cNone\u201d:\n\n.. code-block:: ini\n\n [pytest]\n addopts = --restrict-types None,django.test:SimpleTestCase\n\nHistory\n=======\n\nI developed this feature in a closed source Nose plugin whilst working on the big Django project at YPlan.\nWe 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.\nOur solution was to just make the test runner error if it encountered non-whitelisted test types.\n\nThis package is a pytest port of that plugin.\n",
"bugtrack_url": null,
"license": null,
"summary": "Pytest plugin to restrict the test types allowed",
"version": "4.7.0",
"project_urls": {
"Changelog": "https://github.com/adamchainz/pytest-restrict/blob/main/CHANGELOG.rst",
"Funding": "https://adamj.eu/books/",
"Repository": "https://github.com/adamchainz/pytest-restrict"
},
"split_keywords": [
"class",
" pytest",
" restrict"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "db42d3b82f358d297a653d51f30fdfcb19470698630c92dfa4c2b1699a1a246b",
"md5": "eda0b3d90b51d04c51e9c9ad88a9992d",
"sha256": "32a2b0ceef7e70938100843ebb9ed7bec46b2d279869267ca1adc77979ba0403"
},
"downloads": -1,
"filename": "pytest_restrict-4.7.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "eda0b3d90b51d04c51e9c9ad88a9992d",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.9",
"size": 4820,
"upload_time": "2024-10-24T09:16:56",
"upload_time_iso_8601": "2024-10-24T09:16:56.184093Z",
"url": "https://files.pythonhosted.org/packages/db/42/d3b82f358d297a653d51f30fdfcb19470698630c92dfa4c2b1699a1a246b/pytest_restrict-4.7.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "1cdb50dd4e5351ba5bb4c374a0b0519bac7979037c9ffa1b03c16502ab27a0ff",
"md5": "d238681386634db38f1a50d804a3637c",
"sha256": "98c7fc20dedb47ba2dee0d98fe7834f6fcbd923a58b0b54b2cdf3eda5979fb56"
},
"downloads": -1,
"filename": "pytest_restrict-4.7.0.tar.gz",
"has_sig": false,
"md5_digest": "d238681386634db38f1a50d804a3637c",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.9",
"size": 5605,
"upload_time": "2024-10-24T09:16:57",
"upload_time_iso_8601": "2024-10-24T09:16:57.084020Z",
"url": "https://files.pythonhosted.org/packages/1c/db/50dd4e5351ba5bb4c374a0b0519bac7979037c9ffa1b03c16502ab27a0ff/pytest_restrict-4.7.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-10-24 09:16:57",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "adamchainz",
"github_project": "pytest-restrict",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"tox": true,
"lcname": "pytest-restrict"
}