Temporary insert current directory into sys.path. This can be used by test cases that do runtime imports, for example by the stubgen tests.
()
| 297 | |
| 298 | @contextlib.contextmanager |
| 299 | def local_sys_path_set() -> Iterator[None]: |
| 300 | """Temporary insert current directory into sys.path. |
| 301 | |
| 302 | This can be used by test cases that do runtime imports, for example |
| 303 | by the stubgen tests. |
| 304 | """ |
| 305 | old_sys_path = sys.path.copy() |
| 306 | if not ("" in sys.path or "." in sys.path): |
| 307 | sys.path.insert(0, "") |
| 308 | try: |
| 309 | yield |
| 310 | finally: |
| 311 | sys.path = old_sys_path |
| 312 | |
| 313 | |
| 314 | def testfile_pyversion(path: str) -> tuple[int, int]: |