Skip to content

~95% on SimpleQA (e.g. Qwen3.6-27B on a 3090). Supports all local and cloud LLMs (llama.cpp, Ollama, Google, ...). 10+ search engines - arXiv, PubMed, your private documents. Everything Local & Encrypted.

test(connected): scope collection markers and SQLCipher skip to tests/connected (#6738)

Sebastian Cao0360828914fd
diff --git a/tests/connected/conftest.py b/tests/connected/conftest.py
index 912de4ac94..72ee261445 100644
--- a/tests/connected/conftest.py
+++ b/tests/connected/conftest.py
@@ -50,12 +50,28 @@ def _sqlcipher_available() -> bool:
def pytest_collection_modifyitems(config, items): # noqa: ANN001
"""Stamp every connected test with the ``connected`` marker, and SKIP the
- whole suite (not error) when SQLCipher is unavailable."""
+ whole suite (not error) when SQLCipher is unavailable.
+
+ pytest calls this hook with the WHOLE session's collection, not just the
+ items below this conftest's directory, so filter by path first: without
+ that, merely loading this conftest in a mixed run stamped ``connected``
+ onto every unrelated test, and skipped them all when SQLCipher was
+ missing (#6301).
+ """
+ connected_dir = Path(__file__).resolve().parent
+ connected_items = [
+ item
+ for item in items
+ if getattr(item, "path", None) is not None
+ and item.path.resolve().is_relative_to(connected_dir)
+ ]
+ if not connected_items:
+ return
skip_no_sqlcipher = pytest.mark.skip(
reason="SQLCipher binary not available; connected suite needs encrypted DBs"
)
sqlcipher_ok = _sqlcipher_available()
- for item in items:
+ for item in connected_items:
item.add_marker(pytest.mark.connected)
if not sqlcipher_ok:
item.add_marker(skip_no_sqlcipher)
diff --git a/tests/infrastructure_tests/test_connected_conftest_scoping.py b/tests/infrastructure_tests/test_connected_conftest_scoping.py
new file mode 100644
index 0000000000..2e525a7d2d
--- /dev/null
+++ b/tests/infrastructure_tests/test_connected_conftest_scoping.py
@@ -0,0 +1,178 @@
+# allow: no-sut-import: exercises tests/connected/conftest.py's collection
+# hook (test infrastructure, not package code) in bare pytest subprocesses;
+# the regression must reproduce without the package's dependency tree, so
+# there is nothing from local_deep_research to import here.
+"""Regression: the connected suite's collection hook must stay scoped (#6301).
+
+``tests/connected/conftest.py`` implements ``pytest_collection_modifyitems``,
+which pytest invokes with the WHOLE session's collection, not just items
+below the conftest's directory. It used to loop over every item, so merely
+loading that conftest in a mixed run stamped ``connected`` onto unrelated
+tests (``-m connected`` selected them, ``-m 'not connected'`` excluded
+them), and when the SQLCipher availability probe failed it skip-marked them
+all, a green pytest exit without executing anything.
+
+Everything here runs pytest in fresh subprocesses so the outer session's
+conftests and plugins cannot interfere:
+
+* ``test_real_connected_conftest_does_not_mark_outside_tests`` collects a
+ synthetic outside test file together with the real
+ ``tests/connected/__init__.py``, since loading the real conftest is enough
+ to reproduce the leak (no connected test has to run). ``--confcutdir``
+ keeps the heavyweight root ``tests/conftest.py`` out of the subprocess so
+ this also works on an interpreter without the package installed.
+* the ``mixed_suite`` tests run a pytester-style temp tree whose
+ ``tests/connected/conftest.py`` is the REAL file copied verbatim at
+ runtime, with one trivial test on each side of the boundary. That makes
+ both availability outcomes forceable: ``_sqlcipher_available`` is
+ replaced in the subprocess before pytest starts, and pytest resolves the
+ conftest to the same ``sys.modules`` entry, and lets connected items
+ actually execute or skip without SQLCipher or the package installed.
+"""
+
+import os
+import shutil
+import subprocess
+import sys
+from pathlib import Path
+
+import pytest
+
+REPO_ROOT = Path(__file__).resolve().parents[2]
+REAL_CONNECTED_DIR = REPO_ROOT / "tests" / "connected"
+
+_OUTSIDE_TEST = """\
+def test_outside_one():
+ value = "outside"
+ assert value == "outside"
+
+
+def test_outside_two():
+ assert sorted([2, 1]) == [1, 2]
+"""
+
+_CONNECTED_PROBE_TEST = """\
+def test_connected_probe():
+ assert "connected" in "tests/connected"
+"""
+
+
+def _run_pytest(args, cwd, force_probe=None):
+ """Run pytest in a fresh interpreter and capture its output.
+
+ ``force_probe`` (True/False) pre-imports ``tests.connected.conftest``
+ relative to *cwd* and replaces ``_sqlcipher_available`` before handing
+ control to pytest; pytest then resolves the conftest to that same
+ ``sys.modules`` entry, so the patched probe is the one the collection
+ hook calls. This forces either availability outcome deterministically,
+ without uninstalling anything.
+ """
+ pytest_args = ["-q", "-p", "no:cacheprovider", *[str(a) for a in args]]
+ if force_probe is None:
+ cmd = [sys.executable, "-m", "pytest", *pytest_args]
+ else:
+ script = (
+ "import sys\n"
+ "import pytest\n"
+ "import tests.connected.conftest as connected_conftest\n"
+ f"connected_conftest._sqlcipher_available = lambda: {force_probe!r}\n"
+ f"sys.exit(int(pytest.main({pytest_args!r})))\n"
+ )
+ cmd = [sys.executable, "-c", script]
+ env = {
+ **os.environ,
+ # Determinism: no third-party plugin autoload (xdist/cov/timeout/...)
+ # and no inherited addopts leaking into the subprocess under test.
+ "PYTEST_DISABLE_PLUGIN_AUTOLOAD": "1",
+ "PYTEST_ADDOPTS": "",
+ }
+ return subprocess.run(
+ cmd,
+ cwd=cwd,
+ env=env,
+ capture_output=True,
+ text=True,
+ timeout=120,
+ check=False,
+ )
+
+
+def test_real_connected_conftest_does_not_mark_outside_tests(tmp_path):
+ """Loading the real connected conftest must leave outside tests unmarked.
+
+ This is the issue's reproduction: before the fix, ``-m connected``
+ selected the outside file's tests (exit 0) and ``-m 'not connected'``
+ deselected them (exit 5) as soon as ``tests/connected/__init__.py``
+ appeared on the command line.
+ """
+ outside = tmp_path / "test_outside.py"
+ outside.write_text(_OUTSIDE_TEST)
+ common = [
+ outside,
+ REAL_CONNECTED_DIR / "__init__.py",
+ f"--confcutdir={REAL_CONNECTED_DIR}",
+ "--collect-only",
+ ]
+
+ # Node ids' path prefix varies with the subprocess's rootdir, so match
+ # on the ``::<function>`` part only.
+ selected = _run_pytest([*common, "-m", "connected"], cwd=tmp_path)
+ assert selected.returncode == pytest.ExitCode.NO_TESTS_COLLECTED, (
+ selected.stdout + selected.stderr
+ )
+ assert "::test_outside_one" not in selected.stdout, selected.stdout
+
+ deselected = _run_pytest([*common, "-m", "not connected"], cwd=tmp_path)
+ assert deselected.returncode == pytest.ExitCode.OK, (
+ deselected.stdout + deselected.stderr
+ )
+ assert "::test_outside_one" in deselected.stdout, deselected.stdout
+
+
+def mixed_suite(tmp_path):
+ """A pytester-style mixed tree reusing the REAL connected conftest."""
+ tests_pkg = tmp_path / "tests"
+ connected = tests_pkg / "connected"
+ connected.mkdir(parents=True)
+ (tests_pkg / "__init__.py").write_text("")
+ (connected / "__init__.py").write_text("")
+ shutil.copyfile(
+ REAL_CONNECTED_DIR / "conftest.py", connected / "conftest.py"
+ )
+ (tests_pkg / "test_outside.py").write_text(_OUTSIDE_TEST)
+ (connected / "test_probe.py").write_text(_CONNECTED_PROBE_TEST)
+ return tmp_path
+
+
+def test_marker_selection_is_disjoint_with_sqlcipher_available(mixed_suite):
+ """With the probe forced True, ``-m`` splits the suites cleanly."""
+ connected_run = _run_pytest(
+ ["tests", "-m", "connected"], cwd=mixed_suite, force_probe=True
+ )
+ assert connected_run.returncode == pytest.ExitCode.OK, (
+ connected_run.stdout + connected_run.stderr
+ )
+ assert "1 passed" in connected_run.stdout, connected_run.stdout
+ assert "2 deselected" in connected_run.stdout, connected_run.stdout
+
+ unit_run = _run_pytest(
+ ["tests", "-m", "not connected"], cwd=mixed_suite, force_probe=True
+ )
+ assert unit_run.returncode == pytest.ExitCode.OK, (
+ unit_run.stdout + unit_run.stderr
+ )
+ assert "2 passed" in unit_run.stdout, unit_run.stdout
+ assert "1 deselected" in unit_run.stdout, unit_run.stdout
+
+
+def test_unavailable_sqlcipher_skips_only_connected_tests(mixed_suite):
+ """With the probe forced False, only the connected test skips.
+
+ Before the fix this run reported ``3 skipped``: the outside tests
+ inherited the connected suite's skip and pytest still exited 0.
+ """
+ run = _run_pytest(["tests"], cwd=mixed_suite, force_probe=False)
+ assert run.returncode == pytest.ExitCode.OK, run.stdout + run.stderr
+ assert "2 passed" in run.stdout, run.stdout
+ assert "1 skipped" in run.stdout, run.stdout