Fix/testsuitegate pytest interpreter cwd#195
Conversation
TestSuiteGate.verify ran pytest via a hard-coded python3 interpreter with cwd set to file_path.parent. For nested files this misses the repo's pyproject.toml / pytest.ini / conftest.py and may use a different interpreter/venv than the host process, causing false positives or undiscovered tests and CI-vs-local mismatch. - Run pytest via sys.executable instead of python3. - Set cwd to the resolved project root (project_root or file dir). - Prepend the project root to PYTHONPATH for layouts that rely on it. - Add tests asserting the interpreter, cwd, and PYTHONPATH. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
Warning Rate limit exceeded
You’ve run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
solve #188
TestSuiteGate.verify ran its pytest subprocess with a hard-coded python3 interpreter and cwd set to file_path.parent. When the edited file is nested inside the project, running from the file's own
directory means pytest does not see the repository's pyproject.toml, pytest.ini, or conftest.py, so configuration-dependent tests either fail for the wrong reasons or are not discovered at all.
Hard-coding python3 also risks running under a different interpreter or virtual environment than the host process, which leads to false positives in the verification gate and mismatches between local
and CI behavior.
This change makes the subprocess run in the correct context. pytest is now invoked via sys.executable so it always uses the same interpreter and venv as the host process. The subprocess cwd is set to
the resolved project root (project_root when known, otherwise the file's directory), so pytest discovers the repo's configuration and conftest.py regardless of how deeply the edited file is nested. As
a safety net for project layouts that rely on PYTHONPATH rather than an installed package, the resolved project root is prepended to PYTHONPATH for the subprocess while preserving any existing value.
The change is covered by three new tests in tests/test_test_gate.py that patch subprocess.run to assert the command runs via sys.executable, that cwd is the resolved project root rather than
file_path.parent, and that the project root is present on the subprocess PYTHONPATH. All ten tests in the file pass, and the changed files are clean under black, isort, and flake8.