Skip to main content

Py.test Fixture Configuration

Simple configuration objects for Py.test fixtures. Allows you to skip tests when their required config variables aren’t set.

Installation

Install using your favourite package manager:

pip install pytest-fixture-config
#  or..
easy_install pytest-fixture-config

Enable the fixture explicitly in your tests or conftest.py (not required when using setuptools entry points):

pytest_plugins = ['pytest_fixture_config']

Specifying Configuration

To specify your variables you create a class somewhere in your plugin module, and a singleton instance of the class which reads the variables from wherever you want. In this example we read them from the shell environment:

import os
from pytest_fixture_config import Config

class FixtureConfig(Config):
    __slots__ = ('log_dir', 'log_watcher')

CONFIG=FixtureConfig(
    log_dir=os.getenv('LOG_DIR', '/var/log'),       # This has a default
    log_watcher=os.getenv('LOG_WATCHER'),           # This does not
)

Using Configuration

Simply reference the singleton at run-time in your fixtures:

import pytest

@pytest.fixture
def log_watcher():
    return subprocess.popen([CONFIG.log_watcher, '--log-dir', CONFIG.log_dir])

def test_log_watcher(watcher):
    watcher.communicate()

Skipping tests when things are missing

There are some decorators that allow you to skip tests when settings aren’t set. This is useful when you’re testing something you might not have installed but don’t want your tests suite to fail:

from pytest_fixture_config import requires_config

@requires_config(CONFIG, ['log_watcher', 'log_dir'])
@pytest.fixture
def log_watcher():
    return subprocess.popen([CONFIG.log_watcher, '--log-dir', CONFIG.log_dir])

There is also a version for yield_fixtures:

from pytest_fixture_config import yield_requires_config

@yield_requires_config(CONFIG, ['log_watcher', 'log_dir'])
@pytest.fixture
def log_watcher():
    watcher = subprocess.popen([CONFIG.log_watcher, '--log-dir', CONFIG.log_dir])
    yield watcher
    watcher.kill()

Changelog

1.2.1 (2016-3-1)

  • Fixed pytest-verbose-parametrize for latest version of py.test

1.2.0 (2016-2-19)

  • New plugin: git repository fixture

1.1.1 (2016-2-16)

  • pytest-profiling improvement: escape illegal characters in .prof files (Thanks to Aarni Koskela for the PR)

1.1.0 (2016-2-15)

  • New plugin: devpi server fixture

  • pytest-profiling improvement: overly-long .prof files are saved as the short hash of the test name (Thanks to Vladimir Lagunov for PR)

  • Changed default behavior of workspace.run() to not use a subshell for security reasons

  • Corrected virtualenv.run() method to handle arguments the same as the parent method workspace.run()

  • Removed deprecated ‘–distribute’ from virtualenv args

1.0.1 (2015-12-23)

  • Packaging bugfix

1.0.0 (2015-12-21)

  • Initial public release

Metadata

Release files for pytest-fixture-config 1.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pytest-fixture-config 1.0.1
File Size Uploaded Provenance Actions
pytest-fixture-config-1.0.1.tar.gz 4.3 kB Without provenance Details for pytest-fixture-config-1.0.1.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for pytest-fixture-config 1.0.1
File Interpreter ABI Platform Actions
pytest_fixture_config-1.0.1-py2.7.egg Legacy Egg format - - Details for pytest_fixture_config-1.0.1-py2.7.egg
pytest_fixture_config-1.0.1-py2-none-any.whl Python 2 none any Details for pytest_fixture_config-1.0.1-py2-none-any.whl

Total release size: 12.1 kB

Release files / pytest-fixture-config-1.0.1.tar.gz

Download URL pytest-fixture-config-1.0.1.tar.gz
Size 4.3 kB
Tags Source
SHA-256 checksum
How to use checksums
7d7cc1cb25f88a707f083b1dc2e3c2fdfc6f37709567a2587dd0cd0bcd70edb6
BLAKE2b-256 checksum
How to use checksums
0979432b93dd7c43059d48f37e29a20d95df3a06bb449abdf7c5c1e3cadbcb28
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / pytest_fixture_config-1.0.1-py2.7.egg

Download URL pytest_fixture_config-1.0.1-py2.7.egg
Size 2.9 kB
Tags Egg
SHA-256 checksum
How to use checksums
97704ccd662a4933f577445c9c2bf8633121854781bfbaaba6a473568e1e2170
BLAKE2b-256 checksum
How to use checksums
957efaa0f55770ce2b7fcc6f39d53f92d5e5da88152e8f136a7c07d65a55ee01
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / pytest_fixture_config-1.0.1-py2-none-any.whl

Download URL pytest_fixture_config-1.0.1-py2-none-any.whl
Size 4.9 kB
Tags Python 2
SHA-256 checksum
How to use checksums
9b1a988841457783f55bdc935ca854022e35cc2a6ecd589cfa089f1f8d5c2548
BLAKE2b-256 checksum
How to use checksums
df7b55f67b2cc1ec8bbe737286d9fe33115b2e503bab6d745cc89218d0f87b69
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for pytest-fixture-config 1.0.1

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page