Skip to content

Commit efcc888

Browse files
committed
add --next-gen flag
1 parent 1616434 commit efcc888

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

src/pytest_html/plugin.py

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88

99
from . import extras # noqa: F401
1010
from .html_report import HTMLReport
11-
from .nextgen import NextGenReport
12-
from .nextgen import NextGenSelfContainedReport
11+
from .nextgen import NextGenReport, NextGenSelfContainedReport
1312

1413

1514
def pytest_addhooks(pluginmanager):
@@ -44,6 +43,12 @@ def pytest_addoption(parser):
4443
default=[],
4544
help="append given css file content to report style file.",
4645
)
46+
group.addoption(
47+
"--next-gen",
48+
action="store_true",
49+
default=False,
50+
help="use next-gen report.",
51+
)
4752
parser.addini(
4853
"render_collapsed",
4954
type="bool",
@@ -80,16 +85,17 @@ def pytest_configure(config):
8085
raise OSError(os_error)
8186

8287
if not hasattr(config, "workerinput"):
83-
# prevent opening htmlpath on worker nodes (xdist)
84-
# config._html = HTMLReport(htmlpath, config)
85-
# config.pluginmanager.register(config._html)
88+
# prevent opening html_path on worker nodes (xdist)
8689

87-
if config.getoption("self_contained_html"):
88-
config._next_gen = NextGenSelfContainedReport(html_path, config)
90+
if not config.getoption("next_gen"):
91+
config._html = HTMLReport(html_path, config)
8992
else:
90-
config._next_gen = NextGenReport(html_path, config)
93+
if config.getoption("self_contained_html"):
94+
config._html = NextGenSelfContainedReport(html_path, config)
95+
else:
96+
config._html = NextGenReport(html_path, config)
9197

92-
config.pluginmanager.register(config._next_gen)
98+
config.pluginmanager.register(config._html)
9399

94100

95101
def pytest_unconfigure(config):
@@ -98,11 +104,6 @@ def pytest_unconfigure(config):
98104
del config._html
99105
config.pluginmanager.unregister(html)
100106

101-
next_gen = getattr(config, "_next_gen", None)
102-
if next_gen:
103-
del config._next_gen
104-
config.pluginmanager.unregister(next_gen)
105-
106107

107108
@pytest.hookimpl(tryfirst=True, hookwrapper=True)
108109
def pytest_runtest_makereport(item, call):

0 commit comments

Comments
 (0)