@@ -304,15 +304,34 @@ def test_create_report_path(self, testdir):
304
304
assert result .ret == 0
305
305
assert_results (html )
306
306
307
- @pytest .mark .parametrize ("path" , ["" , "directory" ])
308
- def test_report_title (self , testdir , path ):
307
+ @pytest .mark .parametrize (
308
+ "path, is_custom" , [("" , False ), ("" , True ), ("directory" , False )]
309
+ )
310
+ def test_report_title (self , testdir , path , is_custom ):
309
311
testdir .makepyfile ("def test_pass(): pass" )
312
+
310
313
report_name = "report.html"
314
+ report_title = "My Custom Report" if is_custom else report_name
315
+ if is_custom :
316
+ testdir .makeconftest (
317
+ f"""
318
+ import pytest
319
+ from py.xml import html
320
+
321
+ def pytest_html_report_title(report):
322
+ report.title = "{ report_title } "
323
+ """
324
+ )
325
+
311
326
path = os .path .join (path , report_name )
312
327
result , html = run (testdir , path )
313
328
assert result .ret == 0
314
- report_title = f"<h1>{ report_name } </h1>"
315
- assert report_title in html
329
+
330
+ report_head_title_string = f"<title>{ report_title } </title>"
331
+ assert len (re .findall (report_head_title_string , html )) == 1 , html
332
+
333
+ report_body_title_string = f"<h1>{ report_title } </h1>"
334
+ assert len (re .findall (report_body_title_string , html )) == 1 , html
316
335
317
336
def test_report_title_addopts_env_var (self , testdir , monkeypatch ):
318
337
report_location = "REPORT_LOCATION"
@@ -1073,22 +1092,6 @@ def test_pass():
1073
1092
assert len (re .findall (collapsed_html , html )) == expected_count
1074
1093
assert_results (html , tests = 2 , passed = 1 , failed = 1 )
1075
1094
1076
- def test_custom_content_report_title (self , testdir ):
1077
- content_report_title = str (random .random ())
1078
- testdir .makeconftest (
1079
- f"""
1080
- import pytest
1081
- from py.xml import html
1082
-
1083
- def pytest_html_report_title(report):
1084
- report.title = "title is { content_report_title } "
1085
- """
1086
- )
1087
- testdir .makepyfile ("def test_pass(): pass" )
1088
- result , html = run (testdir )
1089
- assert result .ret == 0
1090
- assert len (re .findall (content_report_title , html )) == 1
1091
-
1092
1095
def test_setup_and_teardown_in_html (self , testdir ):
1093
1096
testdir .makepyfile (
1094
1097
"""
0 commit comments