Common fixtures for pytest
Project description
pytest-fixtures
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 setup.py.
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
test_data
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/conftest.py:
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_data.read('test_integration.output')
assert expected_output == output
Click Fixtures
Fixtures for Click <http://click.pocoo.org/>
cli_runner
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
Links & Contact Info
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
Built Distribution
File details
Details for the file pytest-fixtures-0.1.0.tar.gz
.
File metadata
- Download URL: pytest-fixtures-0.1.0.tar.gz
- Upload date:
- Size: 6.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/39.0.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 28f13dc9fb9206f4a5fba1a100e1b3de20fbfa37a7af440ca07222fa45b85b7b |
|
MD5 | 792d06ac629726e7286c9aa526384618 |
|
BLAKE2b-256 | f7253b7527e005df1dfe040091c3fc6ce75a0670c8e458773678f96d184b3017 |
File details
Details for the file pytest_fixtures-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: pytest_fixtures-0.1.0-py3-none-any.whl
- Upload date:
- Size: 4.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/39.0.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8372ad1cd6dafd7e53b183b8601d1a85cda7bd829e7f73fae18416e95d270a3e |
|
MD5 | 749c2ba3f6fbffd2497d9036d643ad96 |
|
BLAKE2b-256 | 0cd875876c6c77d4f79faaf7ecef0c6532820e4ade5936f4797a8dd4c1ff79db |