Skip to content

Commit 7243c8d

Browse files
feat: ✨ add env variable to help debug issues (#223)
# Description I think we need to go through many types of error messages manually and see if the way the error is presented via `explain` is helpful. This debug option helps with that by always printing the properties dict, its issues, and the output from `explain`. It also enables us to easily do this on all test messages. This is now easy to detect by running the test suite with the debug option enabled, but we still need to make decision about what to do with these errors by opening a new issue for each one of them and discuss the best solutions. Needs an in-depth review. --------- Co-authored-by: Luke W. Johnston <lwjohnst86@users.noreply.github.com>
1 parent 3fc9805 commit 7243c8d

File tree

4 files changed

+30
-0
lines changed

4 files changed

+30
-0
lines changed

justfile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ test-python:
4242
-i coverage.xml \
4343
-o htmlcov/coverage.svg
4444

45+
# View debug information for all tests
46+
# Used to e.g. view output of explain() rather than seeing which tests failed
47+
test-python-debug:
48+
CDP_DEBUG=true uv run pytest -sv
49+
50+
4551
# Check Python code for any errors that need manual attention
4652
check-python:
4753
# Check formatting

src/check_datapackage/check.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import os
12
import re
23
import sys
34
from dataclasses import dataclass, field
@@ -181,6 +182,13 @@ class for more details, especially about the default values.
181182
issues = exclude(issues, config.exclusions)
182183
issues = sorted(set(issues))
183184

185+
# Use by doing `CDP_DEBUG=true uv run ...`
186+
if os.getenv("CDP_DEBUG"):
187+
rprint("", properties)
188+
for issue in issues:
189+
rprint(issue)
190+
rprint(explain([issue]))
191+
184192
if error and issues:
185193
raise DataPackageError(issues)
186194

tests/conftest.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import os
2+
3+
4+
# Can get debug output by using `CDP_DEBUG=true uv run pytest -sv`
5+
def pytest_report_teststatus(report, config):
6+
if os.getenv("CDP_DEBUG"):
7+
if report.when == "call":
8+
# Add newlines to separate test results
9+
category = report.outcome
10+
shortletter = "\n\n" # dot / F / X / etc.
11+
verbose = "\n\n" # ("PASSED", "FAILED", ...)
12+
13+
return category, shortletter, verbose
14+
15+
return None

tools/vulture-allowlist.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44
_check_not_required # unused method (src/check_datapackage/extensions.py:59)
55
_check_field_name_in_jsonpath # unused method (src/check_datapackage/extensions.py:117)
66
cls # unused variable (src/check_datapackage/extensions.py:61)
7+
pytest_report_teststatus # unused function (tests/conftest.py:4)

0 commit comments

Comments
 (0)