diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 0000000..d7f734f --- /dev/null +++ b/tests/conftest.py @@ -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)]) diff --git a/tests/test_management_probe_guards.py b/tests/test_management_probe_guards.py index f5a6a35..340e914 100644 --- a/tests/test_management_probe_guards.py +++ b/tests/test_management_probe_guards.py @@ -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))] diff --git a/tests/test_worktree_imports.py b/tests/test_worktree_imports.py new file mode 100644 index 0000000..115fded --- /dev/null +++ b/tests/test_worktree_imports.py @@ -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()