@@ -11,10 +11,16 @@ def pytest_addoption(parser: "pytest.Parser") -> None:
11
11
"comma-delimited list of the fully-qualified names of "
12
12
"all packages and modules to type-check with beartype"
13
13
)
14
+ skip_help_msg = (
15
+ "comma-delimited list of the fully-qualified names of "
16
+ "all packages and modules to SKIP type-checking with beartype"
17
+ )
14
18
15
19
group = parser .getgroup ("beartype" )
16
20
group .addoption ("--beartype-packages" , action = "store" , help = help_msg )
17
21
parser .addini ("beartype_packages" , type = "args" , help = help_msg )
22
+ group .addoption ("--beartype-skip-packages" , action = "store" , help = skip_help_msg )
23
+ parser .addini ("beartype_skip_packages" , type = "args" , help = skip_help_msg )
18
24
19
25
20
26
def pytest_configure (config : "pytest.Config" ) -> None :
@@ -23,16 +29,28 @@ def pytest_configure(config: "pytest.Config") -> None:
23
29
# "beartype_packages" section in the user-defined "pytest.ini" file, or the
24
30
# "--beartype-packages" options, defined above by the pytest_addoption() hook.
25
31
package_names = config .getini ("beartype_packages" )
26
-
27
32
package_names_arg_str = config .getoption ("beartype_packages" , "" )
28
33
if package_names_arg_str :
29
34
package_names += package_names_arg_str .split ("," )
30
35
36
+ packages_to_skip = config .getini ("beartype_skip_packages" )
37
+ packages_to_skip_arg_str = config .getoption ("beartype_skip_packages" , "" )
38
+ if packages_to_skip_arg_str :
39
+ packages_to_skip += packages_to_skip_arg_str .split ("," )
40
+
41
+ # If `--beartype-packages` is specified (and isn't just `*`),
42
+ # and `--beartype-skip-packages` is also specified, then bail out with an error.
43
+ if package_names and "*" not in package_names and packages_to_skip :
44
+ pytest .exit (
45
+ "'beartype_packages' and 'beartype_skip_packages' cannot be used together."
46
+ )
47
+
31
48
# If the user passed this option...
32
49
if package_names :
33
50
# Defer hook-specific imports. To improve "pytest" startup performance,
34
51
# avoid performing *ANY* imports unless the user actually passed the
35
52
# "--beartype-packages" option declared by this plugin.
53
+ from beartype import BeartypeConf
36
54
from beartype .roar import BeartypeWarning
37
55
from beartype .claw import beartype_all , beartype_packages
38
56
from beartype ._util .text .utiltextjoin import join_delimited
@@ -110,6 +128,6 @@ class BeartypePytestWarning(BeartypeWarning):
110
128
111
129
# Install an import hook type-checking these packages and modules.
112
130
if "*" in package_names :
113
- beartype_all ()
131
+ beartype_all (conf = BeartypeConf ( claw_skip_package_names = packages_to_skip ) )
114
132
else :
115
133
beartype_packages (package_names )
0 commit comments