Skip to content

Commit 67dc737

Browse files
authored
Merge pull request #203 from BeyondEvil/handle-env-var-in-addopts
Handle when report title is stored as an environment variable
2 parents 27b6e77 + 582c29f commit 67dc737

File tree

3 files changed

+27
-3
lines changed

3 files changed

+27
-3
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,5 @@ local.properties
3030

3131
##Tests JS
3232
node_modules/
33+
34+
Pipfile

pytest_html/plugin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ def generate_summary_item(self):
432432

433433
body = html.body(
434434
html.script(raw(main_js)),
435-
html.h1(os.path.basename(session.config.option.htmlpath)),
435+
html.h1(os.path.basename(self.logfile)),
436436
html.p('Report generated on {0} at {1} by '.format(
437437
generated.strftime('%d-%b-%Y'),
438438
generated.strftime('%H:%M:%S')),

testing/test_pytest_html.py

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,12 @@
2121
def run(testdir, path='report.html', *args):
2222
path = testdir.tmpdir.join(path)
2323
result = testdir.runpytest('--html', path, *args)
24+
return result, read_html(path)
25+
26+
27+
def read_html(path):
2428
with open(str(path)) as f:
25-
html = f.read()
26-
return result, html
29+
return f.read()
2730

2831

2932
def assert_results_by_outcome(html, test_outcome, test_outcome_number,
@@ -193,6 +196,25 @@ def test_report_title(self, testdir, path):
193196
report_title = "<h1>{0}</h1>".format(report_name)
194197
assert report_title in html
195198

199+
def test_report_title_addopts_env_var(self, testdir, monkeypatch):
200+
report_location = "REPORT_LOCATION"
201+
report_name = "MuhReport"
202+
monkeypatch.setenv(report_location, report_name)
203+
testdir.makefile(
204+
".ini",
205+
pytest="""
206+
[pytest]
207+
addopts = --html ${0}
208+
""".format(
209+
report_location
210+
),
211+
)
212+
testdir.makepyfile('def test_pass(): pass')
213+
result = testdir.runpytest()
214+
assert result.ret == 0
215+
report_title = "<h1>{0}</h1>".format(report_name)
216+
assert report_title in read_html(report_name)
217+
196218
def test_resources_inline_css(self, testdir):
197219
testdir.makepyfile('def test_pass(): pass')
198220
result, html = run(testdir, 'report.html', '--self-contained-html')

0 commit comments

Comments
 (0)