From ad73d06cbefece8589c1fb20e5f86471e5a78aa5 Mon Sep 17 00:00:00 2001 From: Simon Kohlmeyer Date: Fri, 14 Sep 2018 12:12:00 +0200 Subject: [PATCH] Avoid OSError during django path detection See https://github.com/pytest-dev/pytest-django/issues/641 --- pytest_django/plugin.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pytest_django/plugin.py b/pytest_django/plugin.py index e70772b90..7a85dbf19 100644 --- a/pytest_django/plugin.py +++ b/pytest_django/plugin.py @@ -122,8 +122,14 @@ def _add_django_project_to_path(args): def is_django_project(path): return path.is_dir() and (path / 'manage.py').exists() + def arg_to_path(arg): + # Test classes or functions can be appended to paths separated by :: + arg = arg.split("::", 1)[0] + return pathlib.Path(arg) + def find_django_path(args): - args = [pathlib.Path(x) for x in args if not str(x).startswith("-")] + args = map(str, args) + args = [arg_to_path(x) for x in args if not x.startswith("-")] args = [p for p in args if p.is_dir()] if not args: