Only run tests marked with @pytest.mark.only. If none are marked, all tests run as usual.
Borrowed from mocha.
Installation
pip install pytest-only
Usage
Use it on functions
import pytest
def test_that_will_not_run():
assert 0
@pytest.mark.only
def test_that_will_run():
assert 1
$ py.test -v test_example.py
============================= test session starts ==============================
platform linux -- Python 3.6.1, pytest-3.0.7, py-1.4.33, pluggy-0.4.0 -- /tmp/example/bin/python3.6
cachedir: .cache
rootdir: /tmp/example, inifile:
plugins: only-1.0.0
collected 2 items
test_example.py::test_that_will_run PASSED
=========================== 1 passed in 0.00 seconds ===========================
Or use it on classes
import pytest
class TestThatWillNotRun:
def test_that_will_not_run(self):
assert 0
@pytest.mark.only
class TestThatWillRun:
def test_that_will_run(self):
assert 1
$ py.test -v test_example.py
============================= test session starts ==============================
platform linux -- Python 3.6.1, pytest-3.0.7, py-1.4.33, pluggy-0.4.0 -- /tmp/example/bin/python3.6
cachedir: .cache
rootdir: /tmp/example, inifile:
plugins: only-1.0.0
collected 2 items
test_example.py::TestThatWillRun::test_that_will_run PASSED
=========================== 1 passed in 0.00 seconds ===========================
Or use it on modules
# test_example.py
import pytest
pytestmark = pytest.mark.only
def test_that_will_run():
assert 1
# test_example2.py
def test_that_will_not_run():
assert 0
$ py.test -v test_example.py test_example2.py
============================= test session starts ==============================
platform linux -- Python 3.6.1, pytest-3.0.7, py-1.4.33, pluggy-0.4.0 -- /home/they4kman/.virtualenvs/tmp-53d5944c7c78d28/bin/python3.6
cachedir: .cache
rootdir: /home/they4kman/.virtualenvs/tmp-53d5944c7c78d28, inifile:
plugins: only-1.0.0
collected 2 items
test_example.py::test_that_will_run PASSED
=========================== 1 passed in 0.00 seconds ===========================
Disable for single test run
To run all the tests, regardless of whether @pytest.mark.only is used, pass the --no-only flag to pytest:
$ py.test --no-only
If --no-only has already been passed (perhaps by way of addopts in pytest.ini), use the --only flag to re-enable it:
$ py.test --no-only --only
Pylint checker
If you use pylint, you can avoid committing stray only marks with the bundled plugin. Just enable the pylint checker in your plugins and enable the unexpected-focused rule.
[MASTER]
load-plugins=pytest_only.ext.pylint
[MESSAGES CONTROL]
enable=unexpected-focused
$ cat test_ninja.py
import pytest
@pytest.mark.only
def test_ninja():
pass
$ pylint test_ninja.py
************* Module mymain
test_ninja.py:3:0: W1650: Unexpected focused test(s) using pytest.mark.only: def test_ninja (unexpected-focused)
Development
Install the test/dev requirements using Poetry
poetry installRun the tests
py.testRun the tests on all currently-supported platforms
tox
Metadata
Release files for pytest-only 2.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| pytest_only-2.1.2.tar.gz | 4.9 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pytest_only-2.1.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 11.3 kB
Release files / pytest_only-2.1.2.tar.gz
| Download URL | pytest_only-2.1.2.tar.gz |
|---|---|
| Size | 4.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e341acc083e3bb66debc660b7d5d71ae3b31da5edc2a737280d7304221ab0c29
|
|
BLAKE2b-256 checksum How to use checksums |
1f2f937d554943477a540aa2aae2b4c47ad41c2f089f47691288938c67e94143
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.2 CPython/3.10.14 Linux/5.13.0-52-generic
|
Release files / pytest_only-2.1.2-py3-none-any.whl
| Download URL | pytest_only-2.1.2-py3-none-any.whl |
|---|---|
| Size | 6.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
04dffe2aed64a741145ce5ad25b5df3ae4212e01ff885a8821fd2318eb509e91
|
|
BLAKE2b-256 checksum How to use checksums |
da953cf1a035048ee224a5dc701a3f41a5ec8684b030d217517bdf7da2f545aa
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.2 CPython/3.10.14 Linux/5.13.0-52-generic
|
Security for pytest-only 2.1.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.