@@ -340,12 +340,20 @@ def _prepareconfig(
340
340
raise
341
341
342
342
343
- def _get_directory (path : Path ) -> Path :
344
- """Get the directory of a path - itself if already a directory."""
343
+ def _get_conftest_directory (path : Path ) -> Path :
344
+ """Get the conftest directory of a path.
345
+
346
+ If the path is a directory, this is the path itself, otherwise its parent
347
+ directory.
348
+
349
+ The path is normalized to remove differences between different sources of
350
+ conftest paths which can cause inconsistencies (issue #9765).
351
+ """
345
352
if path .is_file ():
346
- return path .parent
353
+ conftest_directory = path .parent
347
354
else :
348
- return path
355
+ conftest_directory = path
356
+ return Path (os .path .normcase (os .path .normpath (conftest_directory )))
349
357
350
358
351
359
def _get_legacy_hook_marks (
@@ -407,10 +415,10 @@ def __init__(self) -> None:
407
415
# If set, conftest loading is skipped.
408
416
self ._noconftest = False
409
417
410
- # _getconftestmodules()'s call to _get_directory () causes a stat
418
+ # _getconftestmodules()'s call to _get_conftest_directory () causes a stat
411
419
# storm when it's called potentially thousands of times in a test
412
420
# session (#9478), often with the same path, so cache it.
413
- self ._get_directory = lru_cache (256 )(_get_directory )
421
+ self ._get_conftest_directory = lru_cache (256 )(_get_conftest_directory )
414
422
415
423
# plugins that were explicitly skipped with pytest.skip
416
424
# list of (module name, skip reason)
@@ -595,7 +603,7 @@ def _loadconftestmodules(
595
603
if self ._noconftest :
596
604
return
597
605
598
- directory = self ._get_directory (path )
606
+ directory = self ._get_conftest_directory (path )
599
607
600
608
# Optimization: avoid repeated searches in the same directory.
601
609
# Assumes always called with same importmode and rootpath.
@@ -615,7 +623,7 @@ def _loadconftestmodules(
615
623
self ._dirpath2confmods [directory ] = clist
616
624
617
625
def _getconftestmodules (self , path : Path ) -> Sequence [types .ModuleType ]:
618
- directory = self ._get_directory (path )
626
+ directory = self ._get_conftest_directory (path )
619
627
return self ._dirpath2confmods .get (directory , ())
620
628
621
629
def _rget_with_confmod (
0 commit comments