stubtest: Fix wrong assumption about relative path (#12282)
Fixes https://github.com/python/mypy/issues/11019
`run_stubtest` creates temp directory and prepend `sys.path` with relative path (dot `.`) wrongly assuming that the dot will be resolved to absolute path on *every* import attempt.
But in Python dot(`.`) in sys.path is actually resolved by PathFinder and cached in `sys.path_importer_cache` like:
```
sys.path_importer_cache['.']
FileFinder('/somepath/.')
```
later calls for `find_module` return None and import of `test_module` fails. This resulted in only the first test in stubtest's suite passed in non-pytest-xdist environments.
This issue was hidden with bug or feature in pytest-xdist < 2.3.0:
https://github.com/pytest-dev/pytest-xdist/issues/421
It was fixed in pytest-xdist 2.3.0:
https://github.com/pytest-dev/pytest-xdist/pull/667/
- sys.path for pytest-xdist < 2.3.0
`'.', 'project_path', ''`
- sys.path for pytest-xdist >= 2.3.0 or without xdist
`'.', 'project_path'`
In Python for denoting cwd the empty path `''` can be used as a special case, but for readability `sys.path` is prepended with resolved absolute path of temp directory. Also it's essential to restore back `sys.path` after a test to not break subsequent tests.
Signed-off-by: Stanislav Levin <slev@altlinux.org>