Skip to content

Use pytest's importlib import mode by default - #50

Merged
eliotwrobson merged 1 commit into
mainfrom
claude/importlib-import-mode
Nov 18, 2026
Merged

eliotwrobson merged 1 commit into
mainfrom
claude/importlib-import-mode

Conversation

@eliotwrobson

Copy link
Copy Markdown
Collaborator

Fixes #9. Every question's tests are in test_student.py. pytest's default prepend import mode imports each one as the module test_student, so running pytest over several questions stops with an "import file mismatch" error. The plugin now sets --import-mode=importlib, which names each module by its path. It leaves the mode alone if the user chose one, on the command line, in addopts or in PYTEST_ADDOPTS.

In the grader image there's one test_student.py, so the only change there is that /grade/run isn't put on sys.path. Nothing should rely on that: test_student.py already can't import the other files in tests/.

Testing

Installed this branch in the grader image and graded several example questions: codeEditor (correct and timing out), randomFunctionName, fillBlankLastElement, and a question that imports a serverFilesCourse module from the tests, setup code and student code. Scores matched the current image.

🤖 Generated with Claude Code

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@eliotwrobson
eliotwrobson marked this pull request as ready for review November 18, 2026 08:11
@eliotwrobson
eliotwrobson merged commit 97adeb1 into main Nov 18, 2026
5 checks passed
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.

Pytest discovery fails due to duplicated test names

1 participant