Merge pull request #6192 from nicoddemus/remove-reportlog-6180

Remove report_log in favor of pytest-reportlog
This commit is contained in:
Bruno Oliveira
2019-11-18 17:58:37 -03:00
committed by GitHub
10 changed files with 11 additions and 207 deletions

View File

@@ -154,7 +154,6 @@ default_plugins = essential_plugins + (
"assertion",
"junitxml",
"resultlog",
"report_log",
"doctest",
"cacheprovider",
"freeze_support",

View File

@@ -26,7 +26,7 @@ FUNCARGNAMES = PytestDeprecationWarning(
RESULT_LOG = PytestDeprecationWarning(
"--result-log is deprecated and scheduled for removal in pytest 6.0.\n"
"--result-log is deprecated, please try the new pytest-reportlog plugin.\n"
"See https://docs.pytest.org/en/latest/deprecations.html#result-log-result-log for more information."
)

View File

@@ -1,72 +0,0 @@
import json
from pathlib import Path
import pytest
def pytest_addoption(parser):
group = parser.getgroup("terminal reporting", "report-log plugin options")
group.addoption(
"--report-log",
action="store",
metavar="path",
default=None,
help="Path to line-based json objects of test session events.",
)
def pytest_configure(config):
report_log = config.option.report_log
if report_log and not hasattr(config, "slaveinput"):
config._report_log_plugin = ReportLogPlugin(config, Path(report_log))
config.pluginmanager.register(config._report_log_plugin)
def pytest_unconfigure(config):
report_log_plugin = getattr(config, "_report_log_plugin", None)
if report_log_plugin:
report_log_plugin.close()
del config._report_log_plugin
class ReportLogPlugin:
def __init__(self, config, log_path: Path):
self._config = config
self._log_path = log_path
log_path.parent.mkdir(parents=True, exist_ok=True)
self._file = log_path.open("w", buffering=1, encoding="UTF-8")
def close(self):
if self._file is not None:
self._file.close()
self._file = None
def _write_json_data(self, data):
self._file.write(json.dumps(data) + "\n")
self._file.flush()
def pytest_sessionstart(self):
data = {"pytest_version": pytest.__version__, "$report_type": "SessionStart"}
self._write_json_data(data)
def pytest_sessionfinish(self, exitstatus):
data = {"exitstatus": exitstatus, "$report_type": "SessionFinish"}
self._write_json_data(data)
def pytest_runtest_logreport(self, report):
data = self._config.hook.pytest_report_to_serializable(
config=self._config, report=report
)
self._write_json_data(data)
def pytest_collectreport(self, report):
data = self._config.hook.pytest_report_to_serializable(
config=self._config, report=report
)
self._write_json_data(data)
def pytest_terminal_summary(self, terminalreporter):
terminalreporter.write_sep(
"-", "generated report log file: {}".format(self._log_path)
)