From 7d3a5a821c151d0a74d3381e99e2437eff9b16fe Mon Sep 17 00:00:00 2001 From: Robert O'Shea Date: Thu, 28 Jul 2022 23:48:54 +0100 Subject: [PATCH] Fixed error when filename too long --- src/_pytest/config/__init__.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/_pytest/config/__init__.py b/src/_pytest/config/__init__.py index b3173d7d7..a3ab78503 100644 --- a/src/_pytest/config/__init__.py +++ b/src/_pytest/config/__init__.py @@ -528,9 +528,14 @@ class PytestPluginManager(PluginManager): if i != -1: path = path[:i] anchor = absolutepath(current / path) - if anchor.exists(): # we found some file object - self._try_load_conftest(anchor, namespace.importmode, rootpath) - foundanchor = True + try: + if anchor.exists(): # we found some file object + self._try_load_conftest(anchor, namespace.importmode, rootpath) + foundanchor = True + except OSError: + import pytest + + raise pytest.UsageError(f"file or directory not found: {anchor}") if not foundanchor: self._try_load_conftest(current, namespace.importmode, rootpath)