Skip to content

Commit

Permalink
Cast parser to a non-optional Parser.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaraco committed Aug 29, 2024
1 parent 208a16e commit 8657ea1
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions pytest_enabler/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import shlex
import sys
from collections.abc import Container, MutableSequence, Sequence
from typing import TYPE_CHECKING, TypeVar, overload
from typing import TYPE_CHECKING, TypeVar, cast, overload

import toml
from jaraco.context import suppress
Expand Down Expand Up @@ -84,7 +84,14 @@ def _has_plugin(name: str) -> bool:
enabled = {key: plugins[key] for key in plugins if _has_plugin(key)}
for plugin in enabled.values():
args.extend(shlex.split(plugin.get('addopts', "")))
_pytest_cov_check(enabled, early_config, parser, args)
_pytest_cov_check(
enabled,
early_config,
# parser is only used when known not to be None
# based on `enabled` and `early_config`.
cast(Parser, parser),
args,
)


def _remove_deps() -> None:
Expand All @@ -111,7 +118,7 @@ def _remove_deps() -> None:
def _pytest_cov_check(
plugins: Container[str],
early_config: Config,
parser: Parser | None,
parser: Parser,
args: Sequence[str | os.PathLike[str]],
) -> None: # pragma: nocover
"""
Expand All @@ -130,8 +137,6 @@ def _pytest_cov_check(
_remove_deps()
# important: parse all known args to ensure pytest-cov can configure
# itself based on other plugins like pytest-xdist (see #1).
if parser is None:
raise ValueError("parser cannot be None if cov in plugins")
parser.parse_known_and_unknown_args(args, early_config.known_args_namespace)

with contextlib.suppress(ImportError):
Expand Down

0 comments on commit 8657ea1

Please sign in to comment.