Skip to content

Commit 39a5cd3

Browse files
author
Sylvain MARIE
committed
Now using module name and not file path to detect symbols in cases files that are imported from elsewhere and not created locally. Indeed that was causing problems on some ^platforms where a .pyc cache file is created. Fixes #72
1 parent ac69f9d commit 39a5cd3

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

pytest_cases/main_params.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -334,8 +334,11 @@ def extract_cases_from_module(module, # type: ModuleType
334334
# - starting with prefix 'case_'
335335
if f_name.startswith(CASE_PREFIX):
336336
code = _get_code(f)
337-
# check if the function is actually defined in this module (not imported)
338-
if code.co_filename == module.__file__: # or we could use f.__module__ == module.__name__ ?
337+
# check if the function is actually defined in this module (not imported from elsewhere)
338+
# Note: we used code.co_filename == module.__file__ in the past
339+
# but on some targets the file changes to a cached one so this does not work reliably,
340+
# see https://github.com/smarie/python-pytest-cases/issues/72
341+
if f.__module__ == module.__name__:
339342
# - with the optional filter/tag
340343
_tags = getattr(f, CASE_TAGS_FIELD, ())
341344

0 commit comments

Comments
 (0)