Skip to content

terminalreporter prepends a newline on first write if tests are collected #12777

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
dmtucker opened this issue Sep 5, 2024 · 2 comments
Open

Comments

@dmtucker
Copy link

dmtucker commented Sep 5, 2024

# conftest.py
def pytest_terminal_summary(terminalreporter):
    terminalreporter.section("This is a section.")
    terminalreporter.write_line("This is a line.")
    terminalreporter.write_line("This is another line.")
    terminalreporter.section("This is another section.")
    terminalreporter.write_line("This is a 3rd line.")
    terminalreporter.write_line("This is a 4th line.")
$ pipenv run pytest
====================== test session starts =======================
platform linux -- Python 3.10.12, pytest-8.3.2, pluggy-1.5.0
rootdir: /tmp/tmp.WXMdPn0b6L
collected 0 items                                                

======================= This is a section. =======================
This is a line.
This is another line.
==================== This is another section. ====================
This is a 3rd line.
This is a 4th line.
===================== no tests ran in 0.00s ======================
$ pipenv run pytest
====================== test session starts =======================
platform linux -- Python 3.10.12, pytest-8.3.2, pluggy-1.5.0
rootdir: /tmp/tmp.WXMdPn0b6L
collected 1 item                                                 

test_pass.py .                                             [100%]
======================= This is a section. =======================
                                                           <------ Where did this come from?
This is a line.
This is another line.
==================== This is another section. ====================
This is a 3rd line.
This is a 4th line.
======================= 1 passed in 0.00s ========================
@dmtucker
Copy link
Author

dmtucker commented Sep 5, 2024

Interestingly, it doesn't seem to happen running with xdist:

$ pipenv run pytest -n auto
====================== test session starts =======================
platform linux -- Python 3.10.12, pytest-8.3.2, pluggy-1.5.0
rootdir: /tmp/tmp.WXMdPn0b6L
plugins: xdist-3.6.1
8 workers [1 item]      
.                                                          [100%]
======================= This is a section. =======================
This is a line.
This is another line.
==================== This is another section. ====================
This is a 3rd line.
This is a 4th line.
======================= 1 passed in 0.58s ========================

@Oreldm
Copy link

Oreldm commented Sep 6, 2024

Created a PR #12783
Indeed it is coming from the first terminalreporter.write_line("This is a line.").
That's because self.currentfspath = -2 when it's not xdixt :

if not running_xdist:
   self.write_ensure_prefix(line, word, **markup) - > Which Updates self.currentfspath = -2

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

No branches or pull requests

2 participants