Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

- TBD
- add `jmu_pytest_utils.fixtures.observable_stdin`: without something like this, assignments that wish to test the students' messages prompting the user to provide input would have to specify that they must not use the `input()` function's `prompt` parameter because [when run with output redirection (as in testing with `capsys`)), rather than connected to a tty, the input prompts go to stderr](discuss.python.org/t/builtin-function-input-writes-its-prompt-to-sys-stderr-and-not-to-sys-stdout/12955).


## [1.3.0] - 2025-09-17
Expand Down
23 changes: 23 additions & 0 deletions jmu_pytest_utils/fixtures.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
"""Common test fixtures used in many autograders."""

from pytest import fixture


@fixture
def observable_stdin(monkeypatch, capsys):
"""
Fixture that replaces builtins.input so prompts are printed
(capturable by capsys) and test inputs can be fed in.
"""

def _make_observable_stdin(responses):
responses_iter = iter(responses)

def fake_input(prompt=""):
# mimic real input(): print the prompt
print(prompt, end="")
return next(responses_iter)

monkeypatch.setattr("builtins.input", fake_input)

return _make_observable_stdin