pytest-tricks


Fixtures as class attributes (Aug 13, 2017)

Easier migration of unittest-based tests to pytest with fixtures

attributes autouse class fixture ids

Load pytest plugins dynamically (Dec 9, 2016)

Load plugins dynamically by passing plugins to pytest.main()

fixture invocation plugins

ids for fixtures and parametrize (Nov 12, 2016)

set ids by using a str value or generate them with a callable or the pytest_make_parametrize_id hook.

fixture ids parametrize pytest_make_parametrize_id

mark.parametrize with indirect (Jul 10, 2016)

Defer setup code and invoke fixtures from @pytest.mark.parametrize with indirect.

fixture hook indirect marker parametrize

Customize How py.test Collects Tests From Classes (Apr 20, 2016)

Use pytest_pycollect_makeitem to customize how tests are collected from classes

collection hook

Show Pytest Warnings (Apr 8, 2016)

Run pytest with -rw CLI flag to show internal warnings

invocation options reporting warnings

Debug Test Failures With Pdb (Feb 28, 2016)

Combine options -x, -l, --lf and --tb=long to analyze results. Drop to the built-in debugger with --pdb.

debugger invocation options

Create Tests via Parametrization (Feb 23, 2016)

Use @pytest.fixture(params=[1, 2]) or @pytest.mark.parametrize('a, b', [(1, 2), (3, 4)]) to create multiple tests

fixture ids marker parametrize

Shared Directory Between Master and Workers With pytest-xdist (Feb 22, 2016)

Use request.config.slaveinput to send information from master to worker nodes in pytest-xdist

fixture hook xdist

Run Tests Using a Certain Fixture (Feb 21, 2016)

Use the pytest_collection_modifyitems hook to select only tests that use a certain fixture

fixture hook selection