Handle when report title is stored as an environment variable
When the --html flag is used in pytest.ini with "addopts" and the report title is stored in an environment variable, the name of the environment variable was used as the report title. In other words, the environment variable was never expanded. Fixes: #201
This commit is contained in:
parent
27b6e77ab1
commit
582c29fb5a
|
@ -30,3 +30,5 @@ local.properties
|
|||
|
||||
##Tests JS
|
||||
node_modules/
|
||||
|
||||
Pipfile
|
||||
|
|
|
@ -432,7 +432,7 @@ class HTMLReport(object):
|
|||
|
||||
body = html.body(
|
||||
html.script(raw(main_js)),
|
||||
html.h1(os.path.basename(session.config.option.htmlpath)),
|
||||
html.h1(os.path.basename(self.logfile)),
|
||||
html.p('Report generated on {0} at {1} by '.format(
|
||||
generated.strftime('%d-%b-%Y'),
|
||||
generated.strftime('%H:%M:%S')),
|
||||
|
|
|
@ -21,9 +21,12 @@ pytest_plugins = "pytester",
|
|||
def run(testdir, path='report.html', *args):
|
||||
path = testdir.tmpdir.join(path)
|
||||
result = testdir.runpytest('--html', path, *args)
|
||||
return result, read_html(path)
|
||||
|
||||
|
||||
def read_html(path):
|
||||
with open(str(path)) as f:
|
||||
html = f.read()
|
||||
return result, html
|
||||
return f.read()
|
||||
|
||||
|
||||
def assert_results_by_outcome(html, test_outcome, test_outcome_number,
|
||||
|
@ -193,6 +196,25 @@ class TestHTML:
|
|||
report_title = "<h1>{0}</h1>".format(report_name)
|
||||
assert report_title in html
|
||||
|
||||
def test_report_title_addopts_env_var(self, testdir, monkeypatch):
|
||||
report_location = "REPORT_LOCATION"
|
||||
report_name = "MuhReport"
|
||||
monkeypatch.setenv(report_location, report_name)
|
||||
testdir.makefile(
|
||||
".ini",
|
||||
pytest="""
|
||||
[pytest]
|
||||
addopts = --html ${0}
|
||||
""".format(
|
||||
report_location
|
||||
),
|
||||
)
|
||||
testdir.makepyfile('def test_pass(): pass')
|
||||
result = testdir.runpytest()
|
||||
assert result.ret == 0
|
||||
report_title = "<h1>{0}</h1>".format(report_name)
|
||||
assert report_title in read_html(report_name)
|
||||
|
||||
def test_resources_inline_css(self, testdir):
|
||||
testdir.makepyfile('def test_pass(): pass')
|
||||
result, html = run(testdir, 'report.html', '--self-contained-html')
|
||||
|
|
Loading…
Reference in New Issue