Skip to content

Commit

Permalink
Add support for pytest.ini config
Browse files Browse the repository at this point in the history
  • Loading branch information
tusharsadhwani committed Jan 24, 2024
1 parent 10ecfd1 commit dbaf671
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions src/pytest_beartype/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,38 @@
import pytest


def _unquote(string: str) -> str:
"""Remove single and double quotes from a string."""
if len(string) < 2:
return string

if string.startswith("'") and string.endswith("'"):
return string[1:-1]
if string.startswith('"') and string.endswith('"'):
return string[1:-1]

return string


def pytest_addoption(parser: "pytest.Parser") -> None:
# Add beartype-specific "pytest" options exposed by this plugin.
group = parser.getgroup("beartype")
group.addoption(
"--beartype-packages",
action="store",
help=(
"comma-delimited list of the fully-qualified names of "
"all packages and modules to type-check with beartype"
),
help_msg = (
"comma-delimited list of the fully-qualified names of "
"all packages and modules to type-check with beartype"
)

group = parser.getgroup("beartype")
group.addoption("--beartype-packages", action="store", help=help_msg)
parser.addini("beartype_packages", help=help_msg)


def pytest_configure(config: "pytest.Config") -> None:
# Comma-delimited string listing the fully-qualified names of *ALL* packages
# and modules to type-check with beartype, corresponding to the
# "--beartype-packages" option defined above by the pytest_addoption() hook.
package_names_str = config.getoption("beartype_packages")
if package_names_str is None:
package_names_str = _unquote(config.getini("beartype_packages"))

# If the user passed this option...
if package_names_str:
Expand Down

0 comments on commit dbaf671

Please sign in to comment.