Skip to content

Commit 981d0f1

Browse files
Matt Brandtdavehunt
authored andcommitted
Use an env var as the default base_url if one exists (#2)
1 parent c3c6c01 commit 981d0f1

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

README.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,11 @@ You can specify the base URL using a `configuration file`_:
6969
[pytest]
7070
base_url = http://www.example.com
7171
72+
Using an Environment Variable
73+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
74+
75+
You can specify the base URL by setting the ``PYTEST_BASE_URL`` environment variable.
76+
7277
Using a Fixture
7378
^^^^^^^^^^^^^^^
7479

pytest_base_url/plugin.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ def pytest_addoption(parser):
4545
parser.addoption(
4646
'--base-url',
4747
metavar='url',
48+
default=os.getenv('PYTEST_BASE_URL', None),
4849
help='base url for the application under test.')
4950
parser.addoption(
5051
'--verify-base-url',

tests/test_base_url.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,15 @@ def test_skip_config(): pass
5454
""")
5555
result = testdir.runpytest()
5656
assert result.ret == 0
57+
58+
59+
def test_env_var_set(testdir, monkeypatch):
60+
testdir.makepyfile("""
61+
def test_config(request, base_url):
62+
assert request.config.getvalue('base_url')
63+
assert base_url == 'yeehaw'
64+
""")
65+
monkeypatch.setenv('PYTEST_BASE_URL', 'yeehaw')
66+
reprec = testdir.inline_run()
67+
passed, skipped, failed = reprec.listoutcomes()
68+
assert len(passed) == 1

0 commit comments

Comments
 (0)