pytest-directives
Control your tests flow.
Provides directives, that makes process of running tests clear and controllable.
Install:
pip install pytest-directives
Example:
Run your test
- Create test with pytest
# test_something.py
def test_something():
assert False, 'Some product error'
- Describe your flow
# simple_flow.py
import asyncio
import logging
from pytest_directives import sequence
import test_something
simple_flow = sequence(test_something, )
if __name__ == '__main__':
logging.basicConfig(level=logging.DEBUG, format='%(message)s',)
asyncio.run(
simple_flow.run()
)
- Run as usual python code
python simple_flow.py
Using proactor: IocpProactor
Run test from directive PytestRunnable: C:\Users\i.kuzmenko\PycharmProjects\LOCAL\pytest-directives\test_something.py
============================= test session starts =============================
platform win32 -- Python 3.12.10, pytest-8.4.1, pluggy-1.6.0 -- C:\Users\i.kuzmenko\PycharmProjects\LOCAL\pytest-directives\.venv\Scripts\python.exe
rootdir: C:\Users\i.kuzmenko\PycharmProjects\LOCAL\pytest-directives
configfile: pyproject.toml
plugins: asyncio-1.1.0, cov-6.2.1
asyncio: mode=Mode.AUTO, asyncio_default_fixture_loop_scope=function, asyncio_default_test_loop_scope=function
collecting ... collected 1 item
test_something.py::test_something FAILED [100%]
================================== FAILURES ===================================
_______________________________ test_something ________________________________
def test_something():
> assert False, 'Some product error'
E AssertionError: Some product error
E assert False
test_something.py:3: AssertionError
=========================== short test summary info ===========================
FAILED test_something.py::test_something - AssertionError: Some product error
============================== 1 failed in 0.07s ==============================
Errors in tests results
Three main directives
from pytest_directives import sequence, chain, parallel
sequence() # run items one by one; ignore errors
chain() # run items one by one; stop when first fail found
parallel() # run items in parallel; ignore errors
How to run directives
from pytest_directives import sequence
# just import your tests
from tests import test_file_1, test_file_2, test_file_3
# define order in `flow`
sequence_flow = sequence(
test_file_1,
test_file_2,
test_file_3
)
# add some options to pytest
pytest_run_args = (
"-v",
"--alluredir=./allure-results",
)
import asyncio
# start your flow
asyncio.run(
sequence_flow.run(*pytest_run_args)
)
Combine directives in flows
from pytest_directives import sequence, chain, parallel
abstract_flow = sequence(
chain(
chain(
# prepare infrastructure or tests environment
),
# if infrastructure failed, exit from here
parallel(
# run tests in parallel to increase speed of testing
)
),
sequence(
# do some important stuff at the end of tests,
# like collect logs, metrics or just cleanup environment
)
)
smoke_flow = sequence(
chain(
chain(
prepare_environment(),
check_infrastructure_health()
),
parallel(
run_test_group_a(),
run_test_group_B(),
run_api_tests()
),
),
sequence(
collect_logs(),
generate_report(),
cleanup_environment()
)
)
Features
- Can run tests by
importpackage, module, function, class or method - Run pytest in separate process (say no to sharing fixture) by
asyncio.create_subprocess_exec - Can use
pytest.marks/pytest-xdistor other as usual by using.run(*args)parameter - Combine directives and implement your tests flow as you need
Development
- Install uv
- Clone project
- Install requirements
uv sync
Run tests
inv tests
Metadata
Release files for pytest-directives 0.0.3
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 | Actions |
|---|---|---|---|---|
| pytest_directives-0.0.3.tar.gz | 10.2 kB | Without provenance | Details for pytest_directives-0.0.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pytest_directives-0.0.3-py3-none-any.whl | Python 3 | none | any | Details for pytest_directives-0.0.3-py3-none-any.whl |
Total release size: 19.9 kB
Release files / pytest_directives-0.0.3.tar.gz
| Download URL | pytest_directives-0.0.3.tar.gz |
|---|---|
| Size | 10.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f08890cc9e6484cb87261545d804c544011a58d047816c2ba813ab09429da5d9
|
|
BLAKE2b-256 checksum How to use checksums |
e49b8aa3e9e75e213599d35a5dda544a222904c67d9805f1ff62509b5ccc274e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.8.8
|
Release files / pytest_directives-0.0.3-py3-none-any.whl
| Download URL | pytest_directives-0.0.3-py3-none-any.whl |
|---|---|
| Size | 9.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
aafe0e5144e2b778de421de71e8c879e3210e24fc86562f81f42a57c5a32db5e
|
|
BLAKE2b-256 checksum How to use checksums |
aafe51c055f1ac49943e11d683e0c1ed388032cbd9eac9a658a3b5471d79492b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.8.8
|
Security for pytest-directives 0.0.3
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.