-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Closed
Labels
Description
Issue
The following test alters py_info.py on installed virtualenv. While it restores the original content afterwards, the operation changes mtime and therefore invalidates .pyc files.
virtualenv/tests/unit/discovery/py_info/test_py_info.py
Lines 158 to 185 in 08e5dfa
| def test_py_info_cache_invalidation_on_py_info_change(mocker, session_app_data): | |
| # 1. Get a PythonInfo object for the current executable, this will cache it. | |
| PythonInfo.from_exe(sys.executable, session_app_data) | |
| # 2. Spy on _run_subprocess | |
| spy = mocker.spy(cached_py_info, "_run_subprocess") | |
| # 3. Modify the content of py_info.py | |
| py_info_script = Path(cached_py_info.__file__).parent / "py_info.py" | |
| original_content = py_info_script.read_text(encoding="utf-8") | |
| try: | |
| # 4. Clear the in-memory cache | |
| mocker.patch.dict(cached_py_info._CACHE, {}, clear=True) # noqa: SLF001 | |
| py_info_script.write_text(original_content + "\n# a comment", encoding="utf-8") | |
| # 5. Get the PythonInfo object again | |
| info = PythonInfo.from_exe(sys.executable, session_app_data) | |
| # 6. Assert that _run_subprocess was called again | |
| if is_macos_brew(info): | |
| assert spy.call_count in {2, 3} | |
| else: | |
| assert spy.call_count == 2 | |
| finally: | |
| # Restore the original content | |
| py_info_script.write_text(original_content, encoding="utf-8") |
* QA Notice: This package installs one or more compiled Python modules whose
* .py files have different timestamps than recorded:
*
* /usr/lib/pypy3.11/site-packages/virtualenv/discovery/__pycache__/py_info.pypy311.opt-1.pyc
* /usr/lib/pypy3.11/site-packages/virtualenv/discovery/__pycache__/py_info.pypy311.opt-2.pyc
* /usr/lib/pypy3.11/site-packages/virtualenv/discovery/__pycache__/py_info.pypy311.pyc
* /usr/lib/python3.11/site-packages/virtualenv/discovery/__pycache__/py_info.cpython-311.opt-1.pyc
* /usr/lib/python3.11/site-packages/virtualenv/discovery/__pycache__/py_info.cpython-311.opt-2.pyc
* /usr/lib/python3.11/site-packages/virtualenv/discovery/__pycache__/py_info.cpython-311.pyc
* /usr/lib/python3.12/site-packages/virtualenv/discovery/__pycache__/py_info.cpython-312.opt-1.pyc
* /usr/lib/python3.12/site-packages/virtualenv/discovery/__pycache__/py_info.cpython-312.opt-2.pyc
* /usr/lib/python3.12/site-packages/virtualenv/discovery/__pycache__/py_info.cpython-312.pyc
* /usr/lib/python3.13/site-packages/virtualenv/discovery/__pycache__/py_info.cpython-313.opt-1.pyc
* /usr/lib/python3.13/site-packages/virtualenv/discovery/__pycache__/py_info.cpython-313.opt-2.pyc
* /usr/lib/python3.13/site-packages/virtualenv/discovery/__pycache__/py_info.cpython-313.pyc
* /usr/lib/python3.14/site-packages/virtualenv/discovery/__pycache__/py_info.cpython-314.opt-1.pyc
* /usr/lib/python3.14/site-packages/virtualenv/discovery/__pycache__/py_info.cpython-314.opt-2.pyc
* /usr/lib/python3.14/site-packages/virtualenv/discovery/__pycache__/py_info.cpython-314.pyc
Environment
Provide at least:
- OS: Gentoo Linux amd64
pip listof the host python wherevirtualenvis installed: n/a (very long)
Output of the virtual environment creation
n/a