File tree Expand file tree Collapse file tree 2 files changed +43
-1
lines changed Expand file tree Collapse file tree 2 files changed +43
-1
lines changed Original file line number Diff line number Diff line change @@ -32,6 +32,12 @@ def pytest_addoption(parser):
32
32
action = "store_true" ,
33
33
help = "suppresses error messages about imports that cannot be resolved" ,
34
34
)
35
+ group .addoption (
36
+ "--mypy-config-file" ,
37
+ action = "store" ,
38
+ type = str ,
39
+ help = "adds custom mypy config file" ,
40
+ )
35
41
36
42
37
43
XDIST_WORKERINPUT_ATTRIBUTE_NAMES = (
@@ -94,11 +100,19 @@ def pytest_configure_node(self, node): # xdist hook
94
100
if config .getoption ("--mypy-ignore-missing-imports" ):
95
101
mypy_argv .append ("--ignore-missing-imports" )
96
102
103
+ mypy_config_file = config .getoption ("--mypy-config-file" )
104
+ if mypy_config_file :
105
+ mypy_argv .append ("--config-file={}" .format (mypy_config_file ))
106
+
97
107
98
108
def pytest_collect_file (path , parent ):
99
109
"""Create a MypyFileItem for every file mypy should run on."""
100
110
if path .ext in {".py" , ".pyi" } and any (
101
- [parent .config .option .mypy , parent .config .option .mypy_ignore_missing_imports ],
111
+ [
112
+ parent .config .option .mypy ,
113
+ parent .config .option .mypy_config_file ,
114
+ parent .config .option .mypy_ignore_missing_imports ,
115
+ ],
102
116
):
103
117
# Do not create MypyFile instance for a .py file if a
104
118
# .pyi file with the same name already exists;
Original file line number Diff line number Diff line change @@ -129,6 +129,34 @@ def test_mypy_ignore_missings_imports(testdir, xdist_args):
129
129
assert result .ret == 0
130
130
131
131
132
+ def test_mypy_config_file (testdir , xdist_args ):
133
+ """Verify that --mypy-config-file works."""
134
+ testdir .makepyfile (
135
+ """
136
+ def pyfunc(x):
137
+ return x * 2
138
+ """ ,
139
+ )
140
+ result = testdir .runpytest_subprocess ("--mypy" , * xdist_args )
141
+ mypy_file_checks = 1
142
+ mypy_status_check = 1
143
+ mypy_checks = mypy_file_checks + mypy_status_check
144
+ result .assert_outcomes (passed = mypy_checks )
145
+ assert result .ret == 0
146
+ mypy_config_file = testdir .makeini (
147
+ """
148
+ [mypy]
149
+ disallow_untyped_defs = True
150
+ """ ,
151
+ )
152
+ result = testdir .runpytest_subprocess (
153
+ "--mypy-config-file" ,
154
+ mypy_config_file ,
155
+ * xdist_args ,
156
+ )
157
+ result .assert_outcomes (failed = mypy_checks )
158
+
159
+
132
160
def test_mypy_marker (testdir , xdist_args ):
133
161
"""Verify that -m mypy only runs the mypy tests."""
134
162
testdir .makepyfile (
You can’t perform that action at this time.
0 commit comments