pytest-dev / pytest-dev/pytest

Terminal reporter doesn't print

Open
#8,973 7 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

topic: reporting type: bug type: regression
Dominant language
Python
Stars
14.5k
Forks
3.4k
Avg merge
2d 9h
Merged PRs (30d)
35

Description

# test_a.py
def test_foo(request):
    reporter = request.config.pluginmanager.getplugin("terminalreporter")
    reporter.ensure_newline()
    reporter.write("magic", flush=True)

If you run the above file through pytest nothing is written on the output.

$ pytest . 

platform linux -- Python 3.9.6, pytest-6.2.4, py-1.10.0, pluggy-0.13.1
rootdir: /tmp/workdir
plugins: print-0.3.0
collected 1 item

test_a.py .   [100%]

Though I'd expect something like:

$ pytest . 

platform linux -- Python 3.9.6, pytest-6.2.4, py-1.10.0, pluggy-0.13.1
rootdir: /tmp/workdir
plugins: print-0.3.0
collected 1 item

test_a.py
   magic .
   [100%]

Note if you remove the flush we do get the message printed, but without respecting the ensure newline (instead you get test_a.py magic.).

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the test_a.py example with pytest and compare reporter.write behavior with and without flush=True. Inspect the terminalreporter entry points used by request.config.pluginmanager, including ensure_newline() and write(). Done means flushed output preserves the requested newline and displays “magic” in the expected position.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
cli, testing
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.