-
Notifications
You must be signed in to change notification settings - Fork 248
fix: Missing logging in report #603
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -66,11 +66,19 @@ def __init__(self, title, config): | |
"collectedItems": 0, | ||
"runningState": "not_started", | ||
"environment": {}, | ||
"tests": [], | ||
"tests": defaultdict(list), | ||
"resultsTableHeader": {}, | ||
"additionalSummary": defaultdict(list), | ||
} | ||
|
||
@property | ||
def title(self): | ||
return self._data["title"] | ||
|
||
@title.setter | ||
def title(self, title): | ||
self._data["title"] = title | ||
|
||
@property | ||
def config(self): | ||
return self._config | ||
|
@@ -79,19 +87,33 @@ def config(self): | |
def data(self): | ||
return self._data | ||
|
||
def add_test(self, test): | ||
self._data["tests"].append(test) | ||
|
||
def set_data(self, key, value): | ||
self._data[key] = value | ||
|
||
@property | ||
def title(self): | ||
return self._data["title"] | ||
def add_test(self, test_data, report): | ||
# regardless of pass or fail we must add teardown logging to "call" | ||
if report.when == "teardown": | ||
self.update_test_log(report) | ||
|
||
@title.setter | ||
def title(self, title): | ||
self._data["title"] = title | ||
# passed "setup" and "teardown" are not added to the html | ||
if report.when == "call" or _is_error(report): | ||
processed_logs = _process_logs(report) | ||
test_data["log"] = _handle_ansi(processed_logs) | ||
self._data["tests"][report.nodeid].append(test_data) | ||
return True | ||
|
||
return False | ||
|
||
def update_test_log(self, report): | ||
log = [] | ||
for test in self._data["tests"][report.nodeid]: | ||
if test["testId"] == report.nodeid: | ||
for section in report.sections: | ||
header, content = section | ||
if "teardown" in header: | ||
log.append(f" \n{header:-^80} ") | ||
log.append(content) | ||
test["log"] += _handle_ansi("\n".join(log)) | ||
|
||
def __init__(self, report_path, config, default_css="style.css"): | ||
self._report_path = Path(os.path.expandvars(report_path)).expanduser() | ||
|
@@ -269,7 +291,6 @@ def pytest_runtest_logreport(self, report): | |
|
||
data = { | ||
"duration": report.duration, | ||
"when": report.when, | ||
} | ||
|
||
test_id = report.nodeid | ||
|
@@ -291,14 +312,11 @@ def pytest_runtest_logreport(self, report): | |
test_id += f"::{report.when}" | ||
data["testId"] = test_id | ||
|
||
# Order here matters! | ||
log = report.longreprtext or report.capstdout or "No log output captured." | ||
data["log"] = _handle_ansi(log) | ||
data["result"] = _process_outcome(report) | ||
data["extras"] = self._process_extras(report, test_id) | ||
|
||
self._report.add_test(data) | ||
self._generate_report() | ||
if self._report.add_test(data, report): | ||
self._generate_report() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Only generate the report if we actually made a change (added a test in this case). |
||
|
||
|
||
class NextGenReport(BaseReport): | ||
|
@@ -313,8 +331,6 @@ def __init__(self, report_path, config): | |
|
||
@property | ||
def css(self): | ||
# print("woot", Path(self._assets_path.name, "style.css")) | ||
# print("waat", self._css_path.relative_to(self._report_path.parent)) | ||
return Path(self._assets_path.name, "style.css") | ||
|
||
def _data_content(self, content, asset_name, *args, **kwargs): | ||
|
@@ -392,8 +408,25 @@ def _process_css(default_css, extra_css): | |
return css | ||
|
||
|
||
def _is_error(report): | ||
return report.when in ["setup", "teardown"] and report.outcome == "failed" | ||
|
||
|
||
def _process_logs(report): | ||
log = [] | ||
if report.longreprtext: | ||
log.append(report.longreprtext) | ||
for section in report.sections: | ||
header, content = section | ||
log.append(f" \n{header:-^80} ") | ||
log.append(content) | ||
if not log: | ||
log.append("No log output captured.") | ||
return "\n".join(log) | ||
|
||
|
||
def _process_outcome(report): | ||
if report.when in ["setup", "teardown"] and report.outcome == "failed": | ||
if _is_error(report): | ||
return "Error" | ||
if hasattr(report, "wasxfail"): | ||
if report.outcome in ["passed", "failed"]: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ const { getCollapsedCategory } = require('./storage.js') | |
class DataManager { | ||
setManager(data) { | ||
const collapsedCategories = [...getCollapsedCategory(), 'passed'] | ||
const dataBlob = { ...data, tests: data.tests.map((test, index) => ({ | ||
const dataBlob = { ...data, tests: Object.values(data.tests).flat().map((test, index) => ({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This flattens (removes the nodeid key) from the JSON data. |
||
...test, | ||
id: `test_${index}`, | ||
collapsed: collapsedCategories.includes(test.result.toLowerCase()), | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -84,6 +84,7 @@ const dom = { | |
formattedDuration = formatDuration < 1 ? formattedDuration.ms : formattedDuration.formatted | ||
const resultBody = templateResult.content.cloneNode(true) | ||
resultBody.querySelector('tbody').classList.add(resultLower) | ||
resultBody.querySelector('tbody').id = testId | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added this to be able to differentiate between logs using the |
||
resultBody.querySelector('.col-result').innerText = result | ||
resultBody.querySelector('.col-result').classList.add(`${collapsed ? 'expander' : 'collapser'}`) | ||
resultBody.querySelector('.col-result').dataset.id = id | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Made a small performance improvement to avoid having to iterate through all tests, we key them with the original
nodeid
.