Fixture configuration utils for py.test
Project description
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
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 Distributions
File details
Details for the file pytest-fixture-config-1.0.1.tar.gz
.
File metadata
- Download URL: pytest-fixture-config-1.0.1.tar.gz
- Upload date:
- Size: 4.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7d7cc1cb25f88a707f083b1dc2e3c2fdfc6f37709567a2587dd0cd0bcd70edb6 |
|
MD5 | ed5b52b00dda3c177c760f50e3b9817e |
|
BLAKE2b-256 | 0979432b93dd7c43059d48f37e29a20d95df3a06bb449abdf7c5c1e3cadbcb28 |
File details
Details for the file pytest_fixture_config-1.0.1-py2.7.egg
.
File metadata
- Download URL: pytest_fixture_config-1.0.1-py2.7.egg
- Upload date:
- Size: 2.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 97704ccd662a4933f577445c9c2bf8633121854781bfbaaba6a473568e1e2170 |
|
MD5 | 6ab310885eea8c1f5f761e2826a5cf4f |
|
BLAKE2b-256 | 957efaa0f55770ce2b7fcc6f39d53f92d5e5da88152e8f136a7c07d65a55ee01 |
File details
Details for the file pytest_fixture_config-1.0.1-py2-none-any.whl
.
File metadata
- Download URL: pytest_fixture_config-1.0.1-py2-none-any.whl
- Upload date:
- Size: 4.9 kB
- Tags: Python 2
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9b1a988841457783f55bdc935ca854022e35cc2a6ecd589cfa089f1f8d5c2548 |
|
MD5 | 8ce7d3bedec4ddce715093c4c83d3d42 |
|
BLAKE2b-256 | df7b55f67b2cc1ec8bbe737286d9fe33115b2e503bab6d745cc89218d0f87b69 |