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 ===========================
Metadata
Release files for pytest-only 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pytest-only-1.0.0.tar.gz | 2.1 kB | Details |
Release files / pytest-only-1.0.0.tar.gz
| Download URL | pytest-only-1.0.0.tar.gz |
|---|---|
| Size | 2.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5e33341aaa309d6463d205be745a2a7c6d721f6f93eb6c3bac58240e8ecfabf0
|
|
BLAKE2b-256 checksum How to use checksums |
31a3c8c3f03d3b02962c5907ad30bcbfe6aaa5884ac83649862fc829a5088a17
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |