From a140cb81130800d31eae7a4f3aabe39b798b0a80 Mon Sep 17 00:00:00 2001 From: Pavel Karateev Date: Tue, 25 Aug 2026 12:16:47 +0200 Subject: [PATCH] [python] PY-91830 handle the case when `__file__` is `pyc` - Python 3 - `__file__` is always `*.py` - Python 2 - `__file__` could be `*.pyc` if the file is `*.pyc` - `... in step_files` will fail, hence why the relevant test `test_only_step_modules_are_reimported` fails on Python 2 (cherry picked from commit 1ab51b37debb41df12b04a10ff0945b996b8c0ec) IJ-MR-220056 GitOrigin-RevId: 9ff1aa5ffce90cc3eee4fa7b71ffa85bceadcd21 --- python/helpers/pycharm/behave_runner.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/python/helpers/pycharm/behave_runner.py b/python/helpers/pycharm/behave_runner.py index ad3bd1a4fc6b..a444ae2243a1 100644 --- a/python/helpers/pycharm/behave_runner.py +++ b/python/helpers/pycharm/behave_runner.py @@ -107,7 +107,11 @@ def _modules_to_reimport(old_modules, step_files): if name in old_modules or module is None: continue path = getattr(module, '__file__', None) - if not path or os.path.normcase(os.path.abspath(path)) not in step_files: + if not path: + continue + if path.endswith('.pyc'): # Python 2 + path = path[:-1] + if os.path.normcase(os.path.abspath(path)) not in step_files: continue subtree = [name] prefix = name + '.'