Skip to main content

Control your tests flow

Project description

pytest-directives

Control your tests flow.

Provides directives, that makes process of running tests clear and controllable.

Install:

pip install pytest-directives

Example:

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 import package, module, function, class or method
  • Run pytest in separate process (say no to sharing fixture) by asyncio.create_subprocess_exec
  • Combine directives and implement your tests flow as you need

Development

  1. Install uv
  2. Clone project
  3. Install requirements
  uv sync

Run tests

  inv tests

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pytest_directives-0.0.2.tar.gz (9.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pytest_directives-0.0.2-py3-none-any.whl (9.4 kB view details)

Uploaded Python 3

File details

Details for the file pytest_directives-0.0.2.tar.gz.

File metadata

  • Download URL: pytest_directives-0.0.2.tar.gz
  • Upload date:
  • Size: 9.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.8

File hashes

Hashes for pytest_directives-0.0.2.tar.gz
Algorithm Hash digest
SHA256 052eedec3fd0cb53fc03e39d457ffe5635c7bd3153cd6a05d9be0e9240f3add8
MD5 3114a764e15b70e67f41545206d4bb58
BLAKE2b-256 718c142baf3b703c483b414c54fd23ee414c30b857ca8dda870871384ab65f92

See more details on using hashes here.

File details

Details for the file pytest_directives-0.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for pytest_directives-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 3457e84e9e995dc4cbedaf960503d49a141672bf1f620130557b09fa468ea8de
MD5 c373ae4d34474d8d6c5e1a8a19d31eec
BLAKE2b-256 ed1f43bc4cb3165eaa30a1b8ed63ca971e8f47b61d2eff3daaee082a0af191ae

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page