Fixture configuration utils for py.test
Project description
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:
.. code:: bash
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):
.. code:: python
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:
.. code:: python
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:
.. code:: python
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::
.. code:: python
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::
.. code:: python
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.0 (2015-12-21)
~~~~~~~~~~~~~~~~
- Initial public release
=============================
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:
.. code:: bash
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):
.. code:: python
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:
.. code:: python
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:
.. code:: python
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::
.. code:: python
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::
.. code:: python
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.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
Close
Hashes for pytest-fixture-config-1.0.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7bd4a7ce15561cfd513cc2ef31ed6923b97f2e2384f7b5174c501b65586f8f48 |
|
MD5 | a97f0741d11cb49f94da860e454fe05a |
|
BLAKE2b-256 | 6fdf2a7792748f4938aadcf245b793f28d85b78bd9580347298a932e81701ea2 |
Close
Hashes for pytest_fixture_config-1.0.0-py2.7.egg
Algorithm | Hash digest | |
---|---|---|
SHA256 | 85f7846d73477073f5d43de018a0fb9af3aaccea93f4db541e849d7c0eb7bfa9 |
|
MD5 | 3167977e02f57b7073ec864aa07e8363 |
|
BLAKE2b-256 | 6e57042b7f1b70da2fbaa6bd0a733d5d4a444e44b01e8df8b95358dc42448510 |
Close
Hashes for pytest_fixture_config-1.0.0-py2-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0d4092ab204a71c25b2cd207d243f6fed3b80b7ad32df5253381bc52a9a6cfdb |
|
MD5 | 5a44fda469ecdc88ed32e87c24247161 |
|
BLAKE2b-256 | 898eadd51893b4f2bb5d86f83ae912313d4b830f2a7110d07aff462edb7ed9e6 |