Skip to content

Commit 8504758

Browse files
authored
allow to 'skip: True' tests (#15)
1 parent 6d2ec9c commit 8504758

File tree

3 files changed

+25
-10
lines changed

3 files changed

+25
-10
lines changed

pytest_mypy/collect.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from _pytest.config.argparsing import Parser
77

88
from pytest_mypy import utils
9+
from pytest_mypy.utils import string_to_bool
910

1011

1112
class File:
@@ -78,16 +79,18 @@ def collect(self):
7879
expected_output_lines = raw_test.get('out', '').split('\n')
7980
additional_mypy_config = raw_test.get('mypy_config', '')
8081

81-
yield YamlTestItem(name=test_name,
82-
collector=self,
83-
config=self.config,
84-
files=test_files,
85-
starting_lineno=starting_lineno,
86-
environment_variables=extra_environment_variables,
87-
disable_cache=disable_cache,
88-
expected_output_lines=output_from_comments + expected_output_lines,
89-
parsed_test_data=raw_test,
90-
mypy_config=additional_mypy_config)
82+
skip = string_to_bool(str(raw_test.get('skip', 'False')))
83+
if not skip:
84+
yield YamlTestItem(name=test_name,
85+
collector=self,
86+
config=self.config,
87+
files=test_files,
88+
starting_lineno=starting_lineno,
89+
environment_variables=extra_environment_variables,
90+
disable_cache=disable_cache,
91+
expected_output_lines=output_from_comments + expected_output_lines,
92+
parsed_test_data=raw_test,
93+
mypy_config=additional_mypy_config)
9194

9295

9396
def pytest_collect_file(path, parent):

pytest_mypy/tests/test-simple-cases.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,9 @@
6161
a + 1
6262
mypy_config: |
6363
strict_optional = False
64+
65+
- case: skip_incorrect_test_case
66+
skip: yes
67+
main: |
68+
a = 1
69+
reveal_type(a) # N: Revealed type is 'builtins.str'

pytest_mypy/utils.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,3 +327,9 @@ def capture_std_streams() -> Iterator[Tuple[io.StringIO, io.StringIO]]:
327327
err = io.StringIO()
328328
with contextlib.redirect_stdout(out), contextlib.redirect_stderr(err):
329329
yield out, err
330+
331+
332+
def string_to_bool(val: str) -> bool:
333+
from distutils.util import strtobool
334+
335+
return bool(strtobool(val.lower()))

0 commit comments

Comments
 (0)