Pytest plugin which an easy way to run particular gdeploy configuration file during setup phase of a test case. This is useful when there already are some configuration files that can be reused during test setup
Initial structure od this Pytest plugin was generated with Cookiecutter along with @hackebrot's Cookiecutter-pytest-plugin template.
- The plugin provides
gdeploy-config
pytest fixture, which allows one to run one or more gdeploy configuration files during test setup or tear down. - It's compatible with both python2 and python3 (playbooks are executed via
running
gdeploy-config
in subprocess instead of using api of ansible python module).
- gdeploy have to be installed for correct functioning. Use version provided by packaging system of your operation system.
There is no stable release yet, so the only option is to use latest sources from master branch.
The suggested way to install from sources of current master branch is via python virtual enviroment:
$ cd pytest-ansible-playbook $ virtualenv .env $ source .env/bin/activate $ pip install -e .
Note that you can use virtualenvwrapper to simplify this workflow.
When the plugin is installed, there are available following command-line parameters:
py.test \ [--configuration-directory <path_to_directory_with_gdeploy_files>] \ [--gdeploy-configuration-file <name_of_gdeploy_configuration_file>]
Where <path_to_directory_with_gdeploy_files>
is a directory which contains
all gdeploy configuration files that are going to be executed.
A gdeploy-config
process will be able to access the files stored there,
since this directory is set as cwd (current working directory) of the gdeploy
process.
The name_of_configuration_file
is a gdeploy configuration file stored
in <path_to_directory_with_gdeploy_files>
or defined by absolute path.
The plugin provides a single pytest fixture called gdeploy_config
. To
specify configuration files to be executed by gdeploy in the fixture, use the
following `pytest markers`_:
@pytest.mark.gdeploy_config_setup('config.conf')
@pytest.mark.gdeploy_config_teardown('config.conf')
Note that there can be listed multiple files in the marker if needed, eg.:
@pytest.mark.gdeploy_config_setup('config1.conf', 'config2.conf')
Both files would be executed in the given order.
Here is an example how to specify 2 files to be run during setup phase of a test case and one for the teardown:
@pytest.mark.gdeploy_config_setup('volume.conf', 'config2.conf') @pytest.mark.gdeploy_config_teardown('teardown_gluster.conf') def test_foo(gdeploy_config): """ Some testing is done here. """
While using markers without gdeploy_config
fixture like this is valid:
@pytest.mark.gdeploy_config_setup('volume.conf', 'config2.conf') @pytest.mark.gdeploy_config_teardown('teardown_gluster.conf') def test_foo(): """ Some testing is done here. """
no configuration file is executed that way.
Also note that using a marker without any configuration file parameter or using the fixture without any marker is not valid and would cause an error.
Contributions are very welcome. Tests can be run with tox, please ensure the coverage at least stays the same before you submit a pull request.
Distributed under the terms of the Apache Software License 2.0 license, "pytest-gdeploy-config" is free and open source software
If you encounter any problems, please file an issue along with a detailed description.