From 62ea1f9b24812faaf908e396524a99fb205979a8 Mon Sep 17 00:00:00 2001 From: dgtlmoon Date: Tue, 28 Oct 2025 21:02:41 +0100 Subject: [PATCH] Fix paths --- changedetectionio/run_proxy_tests.sh | 15 ++------------- changedetectionio/tests/conftest.py | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/changedetectionio/run_proxy_tests.sh b/changedetectionio/run_proxy_tests.sh index 1eec5669..7abb9fc1 100755 --- a/changedetectionio/run_proxy_tests.sh +++ b/changedetectionio/run_proxy_tests.sh @@ -23,20 +23,9 @@ sleep 5 ## 2nd test actually choose the preferred proxy from proxies.json # This will force a request via "proxy-two" docker run --network changedet-network \ - -v `pwd`/tests/proxy_list/proxies.json-example:/app/changedetectionio/test-datastore/proxies.json \ + -v `pwd`/tests/proxy_list/proxies.json-example:/tmp/proxies.json \ test-changedetectionio \ - bash -c 'echo here is the proxy list; cat /app/changedetectionio/test-datastore/proxies.json; cd changedetectionio && pytest -s tests/proxy_list/test_multiple_proxy.py' - -echo "----------------- SQUID PROXY ONE LOGS -------------" -docker logs squid-one -echo "----------------- SQUID PROXY TWO LOGS -------------" -docker logs squid-two -echo "----- DNS debug output --------" -docker run --network changedet-network test-changedetectionio getent hosts squid-one squid-two -echo "------------------------------------------------------" - -echo "docker ps output" -docker ps + bash -c 'cd changedetectionio && pytest -s tests/proxy_list/test_multiple_proxy.py -d /tmp' set +e echo "- Looking for chosen.changedetection.io request in squid-one - it should NOT be here" diff --git a/changedetectionio/tests/conftest.py b/changedetectionio/tests/conftest.py index 3ac99176..13a2ecab 100644 --- a/changedetectionio/tests/conftest.py +++ b/changedetectionio/tests/conftest.py @@ -97,16 +97,39 @@ def cleanup(datastore_path): if os.path.isfile(f): os.unlink(f) +def pytest_addoption(parser): + """Add custom command-line options for pytest. + + Mirrors main app's -d flag with --datastore-path for consistency. + """ + parser.addoption( + "-d", "--datastore-path", + action="store", + default=None, + help="Custom datastore path for tests (mirrors main app's -d flag)" + ) + @pytest.fixture(scope='session') def datastore_path(tmp_path_factory, request): """Provide datastore path unique to this worker. + Supports custom path via --datastore-path/-d flag (mirrors main app). + CRITICAL for xdist isolation: - Each WORKER gets its own directory - Tests on same worker run SEQUENTIALLY and cleanup between tests - No subdirectories needed since tests don't overlap on same worker - Example: /tmp/test-datastore-gw0/ for worker gw0 """ + # Check for custom path first (mirrors main app's -d flag) + custom_path = request.config.getoption("--datastore-path") + if custom_path: + # Ensure the directory exists + os.makedirs(custom_path, exist_ok=True) + logger.info(f"Using custom datastore path: {custom_path}") + return custom_path + + # Otherwise use default tmp_path_factory logic worker_id = getattr(request.config, 'workerinput', {}).get('workerid', 'master') if worker_id == 'master': path = tmp_path_factory.mktemp("test-datastore")