Skip to content

Monkeypatch the 'pytest_terminal_summary' #6631

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

Closed
viralmutant opened this issue Jan 30, 2020 · 2 comments
Closed

Monkeypatch the 'pytest_terminal_summary' #6631

viralmutant opened this issue Jan 30, 2020 · 2 comments
Labels
topic: reporting related to terminal output and user-facing messages and errors type: question general question, might be closed after 2 weeks of inactivity

Comments

@viralmutant
Copy link

I am using pytest 4.0.0 and I wish to define my own pytest_terminal_summary for a test module

But the existing framework has defined global in top-level conftest.py and using import conftest so my local contest.py doesn't work. I know this is not recommended, but it is what it is :(

Since I can't change hence I am trying to override the pytest_teriminal_summary so I though of monkeypatch it

I was reading through examples and the issue #363 and this is what I am trying

@pytest.fixture(scope="session")
def monkeysession():
    from _pytest.monkeypatch import MonkeyPatch
    mpatch = MonkeyPatch()
    yield mpatch
    mpatch.undo()

@pytest.fixture(scope='session', autouse=True)
def override_terminal(monkeysession):
  def pytest_my_terminal(a,b):
    print("This is my summary")
  monkeysession.setattr(conftest, 'pytest_terminal_summary', pytest_my_terminal)

But it doesn't seem to work. Any other suggestions are also welcome

@Zac-HD Zac-HD added topic: reporting related to terminal output and user-facing messages and errors type: question general question, might be closed after 2 weeks of inactivity labels Feb 1, 2020
@viralmutant
Copy link
Author

Hi
Any suggestions on this ?

@viralmutant
Copy link
Author

I was able to workaround this by having my pytest_terminal_summary hook in py file. Then including that as pytest_plugins=[...] in the test module.
Note: I had to invoke the tests with python3 -m pytest to let it find the locally available module, but that is ok

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: reporting related to terminal output and user-facing messages and errors type: question general question, might be closed after 2 weeks of inactivity
Projects
None yet
Development

No branches or pull requests

2 participants