Skip to content

Commit

Permalink
test: consolidate default environment variables
Browse files Browse the repository at this point in the history
Use pytest to provide default environment variables for testing instead
of defining them in multiple places.

This would enable users to run pytest outisde tox without having to
define extra variables.

Signed-off-by: Sorin Sbarnea <[email protected]>
  • Loading branch information
ssbarnea committed Oct 24, 2019
1 parent 7ae6ea7 commit b4d1465
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
10 changes: 10 additions & 0 deletions conftest.py
Original file line number Diff line number Diff line change
@@ -1 +1,11 @@
import os
import pytest

pytest_plugins = ['helpers_namespace']


@pytest.fixture
def environ():
# adds extra environment variables that may be needed during testing
if not os.environ.get('TEST_BASE_IMAGE', ""):
os.environ['TEST_BASE_IMAGE'] = 'pycontribs/centos:7'
5 changes: 3 additions & 2 deletions molecule/test/functional/docker/test_scenarios.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,10 +218,11 @@ def test_command_test_overrides_driver(
indirect=['scenario_to_test', 'driver_name', 'scenario_name'],
)
def test_command_test_builds_local_molecule_image(
scenario_to_test, with_scenario, scenario_name, driver_name
scenario_to_test, with_scenario, scenario_name, driver_name, environ
):
# with mock.patch.dict('os.environ', environ, clear=True):
try:
image = os.environ.get('TEST_BASE_IMAGE', "docker.io/pycontribs/centos:7")
image = os.environ['TEST_BASE_IMAGE']
cmd = sh.docker.bake('rmi', 'molecule_local/{}'.format(image), '--force')
pytest.helpers.run_command(cmd)
except sh.ErrorReturnCode:
Expand Down
1 change: 0 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ passenv = *
setenv =
ANSIBLE_CALLABLE_WHITELIST={env:ANSIBLE_CALLABLE_WHITELIST:timer,profile_roles}
PYTHONDONTWRITEBYTECODE=1
TEST_BASE_IMAGE=docker.io/pycontribs/centos:7
# -n auto used only on unit as is not supported by functional yet
unit: PYTEST_ADDOPTS=molecule/test/unit/ --cov={toxinidir}/molecule/ --no-cov-on-fail {env:PYTEST_ADDOPTS:-n auto}
functional: PYTEST_ADDOPTS=molecule/test/functional/ {env:PYTEST_ADDOPTS:}
Expand Down

0 comments on commit b4d1465

Please sign in to comment.