Skip to content

Commit 92b179d

Browse files
committed
MAINT: Command-line argument for warnings level
1 parent cb5be2c commit 92b179d

File tree

3 files changed

+38
-5
lines changed

3 files changed

+38
-5
lines changed

haas/plugins/runner.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,21 @@ def __init__(self, warnings=None):
2020

2121
@classmethod
2222
def from_args(cls, args, arg_prefix):
23-
return cls()
23+
return cls(warnings=args.warnings)
2424

2525
@classmethod
2626
def add_parser_arguments(self, parser, option_prefix, dest_prefix):
27-
pass
27+
parser.add_argument(
28+
"--warnings",
29+
default=None,
30+
choices=[
31+
"default", "error", "ignore", "always", "module", "once"
32+
],
33+
help=("Warnings filter action, specifying whether warnings "
34+
"during tests are ignored, displayed, or turned into "
35+
"errors. The interpretation of the different choices "
36+
"matches Python's warnings module.")
37+
)
2838

2939
def run(self, result_collector, test):
3040
"""Run the given test case or test suite.

haas/tests/test_plugin_manager.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,11 @@ def test_driver_hooks_found(self):
116116

117117
# Then
118118
actions = parser._actions
119-
self.assertEqual(len(actions), 1)
120-
action, = actions
121-
self.assertEqual(action.option_strings, ['--runner'])
119+
self.assertEqual(len(actions), 2)
120+
runner_action, warnings_action = sorted(
121+
actions, key=lambda action: action.dest)
122+
self.assertEqual(runner_action.option_strings, ['--runner'])
123+
self.assertEqual(warnings_action.option_strings, ['--warnings'])
122124

123125
def test_get_default_driver(self):
124126
# Given

haas/tests/test_runner.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from argparse import ArgumentParser
2+
13
from mock import Mock, patch
24

35
from ..plugins.runner import BaseTestRunner
@@ -82,3 +84,22 @@ def test(result):
8284
filterwarnings.assert_called_once_with(
8385
'module', category=DeprecationWarning,
8486
message='Please use assert\w+ instead.')
87+
88+
def test_init_from_args(self):
89+
# Given
90+
parser = ArgumentParser()
91+
BaseTestRunner.add_parser_arguments(parser, None, None)
92+
93+
# When
94+
args = parser.parse_args()
95+
runner = BaseTestRunner.from_args(args, None)
96+
97+
# Then
98+
self.assertIsNone(runner.warnings)
99+
100+
# When
101+
args = parser.parse_args(["--warnings", "ignore"])
102+
runner = BaseTestRunner.from_args(args, None)
103+
104+
# Then
105+
self.assertEqual(runner.warnings, "ignore")

0 commit comments

Comments
 (0)