Skip to content

Commit abbe10a

Browse files
feat: --beartype-skip-packages
1 parent 4f50553 commit abbe10a

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[metadata]
22
name = pytest-beartype
3-
version = 0.1.0
3+
version = 0.2.0
44
description = Pytest plugin to run your tests with beartype checking enabled.
55
long_description = file: README.md
66
long_description_content_type = text/markdown

src/pytest_beartype/__init__.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,16 @@ def pytest_addoption(parser: "pytest.Parser") -> None:
1111
"comma-delimited list of the fully-qualified names of "
1212
"all packages and modules to type-check with beartype"
1313
)
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+
)
1418

1519
group = parser.getgroup("beartype")
1620
group.addoption("--beartype-packages", action="store", help=help_msg)
1721
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)
1824

1925

2026
def pytest_configure(config: "pytest.Config") -> None:
@@ -23,16 +29,28 @@ def pytest_configure(config: "pytest.Config") -> None:
2329
# "beartype_packages" section in the user-defined "pytest.ini" file, or the
2430
# "--beartype-packages" options, defined above by the pytest_addoption() hook.
2531
package_names = config.getini("beartype_packages")
26-
2732
package_names_arg_str = config.getoption("beartype_packages", "")
2833
if package_names_arg_str:
2934
package_names += package_names_arg_str.split(",")
3035

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+
3148
# If the user passed this option...
3249
if package_names:
3350
# Defer hook-specific imports. To improve "pytest" startup performance,
3451
# avoid performing *ANY* imports unless the user actually passed the
3552
# "--beartype-packages" option declared by this plugin.
53+
from beartype import BeartypeConf
3654
from beartype.roar import BeartypeWarning
3755
from beartype.claw import beartype_all, beartype_packages
3856
from beartype._util.text.utiltextjoin import join_delimited
@@ -110,6 +128,6 @@ class BeartypePytestWarning(BeartypeWarning):
110128

111129
# Install an import hook type-checking these packages and modules.
112130
if "*" in package_names:
113-
beartype_all()
131+
beartype_all(conf=BeartypeConf(claw_skip_package_names=packages_to_skip))
114132
else:
115133
beartype_packages(package_names)

0 commit comments

Comments
 (0)