-
Notifications
You must be signed in to change notification settings - Fork 0
feat: Add optional debug output #223
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
base: main
Are you sure you want to change the base?
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 |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| import os | ||
|
|
||
|
|
||
| def pytest_report_teststatus(report, config): | ||
| if os.getenv("CDP_DEBUG"): | ||
| if report.when == "call": | ||
| # Add newlines to separate test results | ||
| category = report.outcome | ||
| shortletter = "\n\n" # dot / F / X / etc. | ||
| verbose = "\n\n" # ("PASSED", "FAILED", ...) | ||
|
|
||
| return category, shortletter, verbose | ||
|
|
||
| return None | ||
|
Comment on lines
+4
to
+14
Contributor
Author
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. We can already get debug output from tests by running them with: CDP_DEBUG=true uv run pytest -sv tests/test_check.py However, it gets hard to see what output belongs to which tests since there is no separation:
("PASSED" belongs to the previous test and tests melts into each other) With this little code snippet in conftest.py, the output is easier to read:
(I'm thinking we don't need the test status since we would just use this to look at formatting but it could easily be added back in)
|
||


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.
To activate, you can run a script like this:
I tried fancier solutions with the rich logging module, but it was impossible for me to find a way that
pytestwould pipe through the colors of the output fromrichwhen using the logging handler. With printing it "just works" (tm).There is also no built-in way to pass a debug level flag to Python's logging module, so we would en up reading an env variable or making our script accept a command line parameter, which both seemed like unnecessary code.
As an example of output, let's run this command:
CDP_DEBUG=true uv run python -c 'import check_datapackage as cdp; cdp.check({"resources": [{"title": "Title"}]})'which gives us:
It is easy to inspect the two error message from
explainthis way. In this case, the first one seems to make sense whereas the second doesn't make it clear what went wrong (it seems like we passed something to name so why is it telling us it didn't). Follow up on @martonvago 's comment in #208 (comment)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.
I put a comment on the issue about this too 😅