Skip to content

Commit

Permalink
Add new 'warnings' setting + enable warnings by default (#272)
Browse files Browse the repository at this point in the history
This commit adds a `"warnings"` setting set to `"default"` to print python warnings to console during tests.

That's the default behavior of unittest CLI.

---------

Signed-off-by: Giampaolo Rodola <[email protected]>
Co-authored-by: deathaxe <[email protected]>
  • Loading branch information
giampaolo and deathaxe authored Jun 2, 2024
1 parent caa1465 commit 190d642
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 0 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -317,13 +317,26 @@ window.run_command("unit_testing", {"package": "$package_name", "coverage": Fals
| failfast | stop early if a test fails | false |
| output | name of the test output instead of showing <br> in the panel | null |
| verbosity | verbosity level | 2 |
| warnings | The warnings filter controls python warnings treatment. | "default" |
| capture_console | capture stdout and stderr in the test output | false |
| reload_package_on_testing | reloading package will increase coverage rate | true |
| coverage | track test case coverage | false |
| coverage_on_worker_thread | (experimental) | false |
| generate_html_report | generate HTML report for coverage | false |
| generate_xml_report | generate XML report for coverage | false |

Valid `warnings` values are:

| Value | Disposition
| --------- | -----------
| "default" | print the first occurrence of matching warnings for each location (module + line number) where the warning is issued
| "error" | turn matching warnings into exceptions
| "ignore" | never print matching warnings
| "always" | always print matching warnings
| "module" | print the first occurrence of matching warnings for each module where the warning is issued (regardless of line number)
| "once" | print only the first occurrence of matching warnings, regardless of location

see also: https://docs.python.org/3/library/warnings.html#warning-filter

## Writing Unittests

Expand Down
13 changes: 13 additions & 0 deletions sublime-package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,19 @@
"default": 2,
"markdownDescription": "Verbosity level.",
},
"warnings": {
"enum": ["default", "error", "ignore", "always", "module", "once"],
"enumDescriptions": [
"print the first occurrence of matching warnings for each location (module + line number) where the warning is issued",
"turn matching warnings into exceptions",
"never print matching warnings",
"always print matching warnings",
"print the first occurrence of matching warnings for each module where the warning is issued (regardless of line number)",
"print only the first occurrence of matching warnings, regardless of location"
],
"default": "default",
"markdownDescription": "The warnings filter controls whether warnings are ignored, displayed, or turned into errors (raising an exception).",
},
"output": {
"type": ["string", "null"],
"markdownDescription": "Name of the test output instead of showing in the panel.",
Expand Down
1 change: 1 addition & 0 deletions unittesting/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
# output
"output": None,
"verbosity": 2,
"warnings": "default",
"capture_console": False,
# reloader
"reload_package_on_testing": True,
Expand Down
2 changes: 2 additions & 0 deletions unittesting/unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ def run_tests(self, stream, package, settings, cleanup_hooks=[]):
testRunner = DeferringTextTestRunner(
stream=stream,
verbosity=settings["verbosity"],
warnings=settings["warnings"],
failfast=settings["failfast"],
condition_timeout=settings["condition_timeout"],
)
Expand All @@ -231,6 +232,7 @@ def run_tests(self, stream, package, settings, cleanup_hooks=[]):
testRunner = TextTestRunner(
stream,
verbosity=settings["verbosity"],
warnings=settings["warnings"],
failfast=settings["failfast"],
)

Expand Down

0 comments on commit 190d642

Please sign in to comment.