Skip to content

Commit 190d642

Browse files
giampaolodeathaxe
andauthored
Add new 'warnings' setting + enable warnings by default (#272)
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 <g.rodola@gmail.com> Co-authored-by: deathaxe <deathaxe82@googlemail.com>
1 parent caa1465 commit 190d642

File tree

4 files changed

+29
-0
lines changed

4 files changed

+29
-0
lines changed

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,13 +317,26 @@ window.run_command("unit_testing", {"package": "$package_name", "coverage": Fals
317317
| failfast | stop early if a test fails | false |
318318
| output | name of the test output instead of showing <br> in the panel | null |
319319
| verbosity | verbosity level | 2 |
320+
| warnings | The warnings filter controls python warnings treatment. | "default" |
320321
| capture_console | capture stdout and stderr in the test output | false |
321322
| reload_package_on_testing | reloading package will increase coverage rate | true |
322323
| coverage | track test case coverage | false |
323324
| coverage_on_worker_thread | (experimental) | false |
324325
| generate_html_report | generate HTML report for coverage | false |
325326
| generate_xml_report | generate XML report for coverage | false |
326327

328+
Valid `warnings` values are:
329+
330+
| Value | Disposition
331+
| --------- | -----------
332+
| "default" | print the first occurrence of matching warnings for each location (module + line number) where the warning is issued
333+
| "error" | turn matching warnings into exceptions
334+
| "ignore" | never print matching warnings
335+
| "always" | always print matching warnings
336+
| "module" | print the first occurrence of matching warnings for each module where the warning is issued (regardless of line number)
337+
| "once" | print only the first occurrence of matching warnings, regardless of location
338+
339+
see also: https://docs.python.org/3/library/warnings.html#warning-filter
327340

328341
## Writing Unittests
329342

sublime-package.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,19 @@
3131
"default": 2,
3232
"markdownDescription": "Verbosity level.",
3333
},
34+
"warnings": {
35+
"enum": ["default", "error", "ignore", "always", "module", "once"],
36+
"enumDescriptions": [
37+
"print the first occurrence of matching warnings for each location (module + line number) where the warning is issued",
38+
"turn matching warnings into exceptions",
39+
"never print matching warnings",
40+
"always print matching warnings",
41+
"print the first occurrence of matching warnings for each module where the warning is issued (regardless of line number)",
42+
"print only the first occurrence of matching warnings, regardless of location"
43+
],
44+
"default": "default",
45+
"markdownDescription": "The warnings filter controls whether warnings are ignored, displayed, or turned into errors (raising an exception).",
46+
},
3447
"output": {
3548
"type": ["string", "null"],
3649
"markdownDescription": "Name of the test output instead of showing in the panel.",

unittesting/base.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
# output
2121
"output": None,
2222
"verbosity": 2,
23+
"warnings": "default",
2324
"capture_console": False,
2425
# reloader
2526
"reload_package_on_testing": True,

unittesting/unit.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ def run_tests(self, stream, package, settings, cleanup_hooks=[]):
223223
testRunner = DeferringTextTestRunner(
224224
stream=stream,
225225
verbosity=settings["verbosity"],
226+
warnings=settings["warnings"],
226227
failfast=settings["failfast"],
227228
condition_timeout=settings["condition_timeout"],
228229
)
@@ -231,6 +232,7 @@ def run_tests(self, stream, package, settings, cleanup_hooks=[]):
231232
testRunner = TextTestRunner(
232233
stream,
233234
verbosity=settings["verbosity"],
235+
warnings=settings["warnings"],
234236
failfast=settings["failfast"],
235237
)
236238

0 commit comments

Comments
 (0)