Skip to content

Fix/testsuitegate pytest interpreter cwd#195

Open
shrutu0929 wants to merge 2 commits into
Refactron-ai:mainfrom
shrutu0929:fix/testsuitegate-pytest-interpreter-cwd
Open

Fix/testsuitegate pytest interpreter cwd#195
shrutu0929 wants to merge 2 commits into
Refactron-ai:mainfrom
shrutu0929:fix/testsuitegate-pytest-interpreter-cwd

Conversation

@shrutu0929
Copy link
Copy Markdown

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.

shrutu0929 and others added 2 commits April 7, 2026 18:31
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>
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 15, 2026

Warning

Rate limit exceeded

@shrutu0929 has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 47 minutes and 19 seconds before requesting another review.

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 @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: a4985aa2-d777-465d-86a4-e2b26efb5c8f

📥 Commits

Reviewing files that changed from the base of the PR and between 2f04295 and 16f4bb9.

📒 Files selected for processing (2)
  • refactron/verification/checks/test_gate.py
  • tests/test_test_gate.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant