Skip to main content

Common fixtures for pytest

Project description


Common fixtures for pytest

To use, just install it and pytest will automatically detect and load all fixtures:

pip install pytest-fixtures

To install automatically, add it to your test requirements in tox.ini or

No Dependencies

This package does not depend on any other packages and never will. It uses standard libraries or uses run-time imports and therefore it is lightweight to add to any project. As for which external run-time dependency a fixture needs, that is documented here and shouldn’t matter as you would only use the fixtures that your project already has dependencies on.

Standard Fixtures

Fixtures based on standard Python libraries


To get path, read, and write test data in tests/data folder, use the test_data fixture.

First, setup the path to test data path in tests/

from pathlib import Path
from fixtures import TestData

TestData.BASE_PATH = Path(__file__).parent / 'data'

And then get path to data files in tests/data using test_data fixture:

def test_integration(test_data):
    obj = MyClass(test_data.path('sample.csv'))

To write out test data:

def test_integration(test_data):
    output = run_cli()
    test_data.write('test_integration.output', output)

Then read the test data to assert:

def test_integration(test_data):
    output = run_cli()
    expected_output ='test_integration.output')
    assert expected_output == output

Click Fixtures

Fixtures for Click <>


To invoke, assert exit, with stdout/stderr outputs on error:

.. code-block:: python
def test_cli(cli_runner):
result = cli_runner.invoke( … ) # Prints out stdout/stderr from result with headings result = cli_runner.invoke_and_assert_exit(0, … ) # Same as above and asserts exit code == 0

Project details

Download files

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

Files for pytest-fixtures, version 0.1.0
Filename, size File type Python version Upload date Hashes
Filename, size pytest_fixtures-0.1.0-py3-none-any.whl (4.9 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size pytest-fixtures-0.1.0.tar.gz (6.3 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page