config: let main() accept any os.PathLike instead of just py.path.local
Really it ought to only take the List[str], but for backward compatibility, at least get rid of the explicit py.path.local check.
This commit is contained in:
parent
73586be08f
commit
2c05a7babb
|
@ -128,7 +128,7 @@ def filter_traceback_for_conftest_import_failure(
|
||||||
|
|
||||||
|
|
||||||
def main(
|
def main(
|
||||||
args: Optional[Union[List[str], py.path.local]] = None,
|
args: Optional[Union[List[str], "os.PathLike[str]"]] = None,
|
||||||
plugins: Optional[Sequence[Union[str, _PluggyPlugin]]] = None,
|
plugins: Optional[Sequence[Union[str, _PluggyPlugin]]] = None,
|
||||||
) -> Union[int, ExitCode]:
|
) -> Union[int, ExitCode]:
|
||||||
"""Perform an in-process test run.
|
"""Perform an in-process test run.
|
||||||
|
@ -295,13 +295,15 @@ def get_plugin_manager() -> "PytestPluginManager":
|
||||||
|
|
||||||
|
|
||||||
def _prepareconfig(
|
def _prepareconfig(
|
||||||
args: Optional[Union[py.path.local, List[str]]] = None,
|
args: Optional[Union[List[str], "os.PathLike[str]"]] = None,
|
||||||
plugins: Optional[Sequence[Union[str, _PluggyPlugin]]] = None,
|
plugins: Optional[Sequence[Union[str, _PluggyPlugin]]] = None,
|
||||||
) -> "Config":
|
) -> "Config":
|
||||||
if args is None:
|
if args is None:
|
||||||
args = sys.argv[1:]
|
args = sys.argv[1:]
|
||||||
elif isinstance(args, py.path.local):
|
# TODO: Remove type-ignore after next mypy release.
|
||||||
args = [str(args)]
|
# https://github.com/python/typeshed/commit/076983eec45e739c68551cb6119fd7d85fd4afa9
|
||||||
|
elif isinstance(args, os.PathLike): # type: ignore[misc]
|
||||||
|
args = [os.fspath(args)]
|
||||||
elif not isinstance(args, list):
|
elif not isinstance(args, list):
|
||||||
msg = "`args` parameter expected to be a list of strings, got: {!r} (type: {})"
|
msg = "`args` parameter expected to be a list of strings, got: {!r} (type: {})"
|
||||||
raise TypeError(msg.format(args, type(args)))
|
raise TypeError(msg.format(args, type(args)))
|
||||||
|
|
|
@ -277,7 +277,7 @@ class TestCollectPluginHookRelay:
|
||||||
wascalled.append(path)
|
wascalled.append(path)
|
||||||
|
|
||||||
pytester.makefile(".abc", "xyz")
|
pytester.makefile(".abc", "xyz")
|
||||||
pytest.main(py.path.local(pytester.path), plugins=[Plugin()])
|
pytest.main(pytester.path, plugins=[Plugin()])
|
||||||
assert len(wascalled) == 1
|
assert len(wascalled) == 1
|
||||||
assert wascalled[0].ext == ".abc"
|
assert wascalled[0].ext == ".abc"
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue