Skip to content

Commit 59df8fd

Browse files
committed
tests/test_vagrant.py: Allow to set provider from env variables
Current provider is hardcoded inside the test file. We may want to switch easily between test providers (local testing, using something else than GHA, whatever...) so add a new function used to return the current test provider. Changing the test provider is done by setting an environment variable since any code / logic to detect the provider to use will always be broken. Signed-off-by: Arnaud Patard <apatard@hupstream.com>
1 parent e21a349 commit 59df8fd

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

tests/test_vagrant.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,20 @@
3030
import vagrant
3131
from vagrant import compat
3232

33+
34+
# must be defined before TEST_PROVIDER.
35+
def get_provider() -> str:
36+
"""
37+
Return the provider to use for testing and allow to set it
38+
with PYTHON_VAGRANT_TEST_PROVIDER environment variable is set.
39+
Defauts to virtualbox
40+
"""
41+
my_prov = "virtualbox"
42+
if "PYTHON_VAGRANT_TEST_PROVIDER" in os.environ:
43+
my_prov = os.environ["PYTHON_VAGRANT_TEST_PROVIDER"]
44+
return my_prov
45+
46+
3347
# location of Vagrant executable
3448
VAGRANT_EXE = vagrant.get_vagrant_executable()
3549

@@ -53,7 +67,7 @@
5367
# name of the base box used for testing
5468
TEST_BOX_URL = "generic/alpine315"
5569
TEST_BOX_NAME = TEST_BOX_URL
56-
TEST_PROVIDER = "virtualbox"
70+
TEST_PROVIDER = get_provider()
5771
TEST_DUMMY_BOX_URL = os.path.join(
5872
os.path.dirname(os.path.abspath(__file__)), "tools", f"dummy-{TEST_PROVIDER}.box"
5973
)

tox.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ commands =
2626
--no-cov-on-fail \
2727
}
2828
passenv =
29+
PYTHON_VAGRANT_TEST_PROVIDER
2930
# Pass HOME to the test environment as it is required by
3031
# vagrant. Otherwise error happens due to missing HOME env variable.
3132
HOME

0 commit comments

Comments
 (0)