test: keep subprocess imports on the active worktree
This commit is contained in:
1 parent
eabf61c73b
commit
5b7e7bea2f
3 files changed
+26
-1
No files matched your search
@@ -0,0 +1,10 @@
|
||||
"""Keep subprocess imports on the worktree being tested."""
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
def pytest_configure():
|
||||
source = str(Path(__file__).resolve().parents[1] / 'src')
|
||||
existing = os.environ.get('PYTHONPATH', '').split(os.pathsep)
|
||||
os.environ['PYTHONPATH'] = os.pathsep.join(
|
||||
[source, *(entry for entry in existing if entry and entry != source)])
|
||||
@@ -147,7 +147,8 @@ def test_mapping_context_is_serialized_and_restored_before_catalog(tmp_path, mon
|
||||
order.append(('mapping', drive, remote)))
|
||||
monkeypatch.setattr(native, '_catalog_native', lambda job, root:
|
||||
(order.append(('catalog', job['library'])) or {'success': True, 'safe_to_continue': True}))
|
||||
assert native.management_worker_main(tmp_path/'catalog/request.json') == 0
|
||||
assert captured[0]['worker_role'] == 'catalog_readonly'
|
||||
assert native.catalog_worker_main(tmp_path/'catalog/request.json') == 0
|
||||
assert order == [('mapping', 'S:', r'\\server\share'), ('catalog', str(library))]
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
"""A spawned Python must test the same worktree as its pytest parent."""
|
||||
import json
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
|
||||
def test_spawned_python_imports_active_worktree_from_another_directory(tmp_path):
|
||||
import cbb_refresh_verify
|
||||
child = subprocess.run(
|
||||
[sys.executable, '-c', 'import json,cbb_refresh_verify; '
|
||||
'print(json.dumps(cbb_refresh_verify.__file__))'],
|
||||
cwd=tmp_path, capture_output=True, text=True, check=True, timeout=10)
|
||||
assert Path(json.loads(child.stdout)).resolve() == Path(cbb_refresh_verify.__file__).resolve()
|
||||
Reference in new issue
Block a user