Skip to content

Disable monkey patching "mock" when --tb is set to native - #46

Merged
nicoddemus merged 1 commit into
masterfrom
44-duplicated-traceback
Jun 1, 2016
Merged

nicoddemus merged 1 commit into
masterfrom
44-duplicated-traceback

Conversation

@nicoddemus

Copy link
Copy Markdown
Member

The mechanism we use to hide traceback entries from the mock module does not work on native tracebacks anyway, so it makes sense to automatically disable it in that situation.

This also takes care of the duplicated tracebacks on Python 3.5. @blueyed could you try this out and tell what do you think?

Fix #44

@coveralls

Copy link
Copy Markdown

Coverage Status

Coverage remained the same at 100.0% when pulling dfd2603 on 44-duplicated-traceback into a6993b7 on master.

Comment thread CHANGELOG.rst
``repr`` string as well as related assertion failure messages.
Thanks `@jurko-gospodnetic`_ for the PR (`#40`_).

* Monkey patching is automatically disabled with the ``--tb=native`` option. The underlying

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm I should change this to:

Monkey patching ``mock`` module for friendlier tracebacks is automatically disabled 
with the ``--tb=native`` option.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You didn't yet 😉

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, thanks for the reminder. 😁

@nicoddemus

Copy link
Copy Markdown
Member Author

@blueyed did you get a chance of trying this out? 😁

@blueyed

blueyed commented May 31, 2016

Copy link
Copy Markdown
Contributor

Thanks, I have not tried it yet - sorry.

Would it make sense to display a warning/info message in case it gets automatically disabled?
That would be useful especially when you try to explicitly enable / use it (and not if it's just the default).

@nicoddemus

Copy link
Copy Markdown
Member Author

Would it make sense to display a warning/info message in case it gets automatically disabled?

Hmmm it does make sense, not sure how to display this warning though. How about:

$ py.test --tb=native
============================= test session starts =============================
platform win32 -- Python 2.7.11, pytest-2.9.0, py-1.4.31, pluggy-0.3.1
qt-api: pyqt5
mock: monkeypatching disabled because of --tb=native
rootdir: x:/projects, inifile: pytest.ini
plugins: mock-0.11.0, qt-1.3.0,
collecting...

@blueyed

blueyed commented Jun 1, 2016

Copy link
Copy Markdown
Contributor

mock: monkeypatching disabled because of --tb=native

👍

Also the PR works in general as advertised.

@nicoddemus

Copy link
Copy Markdown
Member Author

@The-Compiler what do you think? 😁

Comment thread test_pytest_mock.py
assert result.ret == 1
assert 'Traceback (most recent call last)' in result.stdout.str()
assert 'During handling of the above exception' not in result.stdout.str()
assert 'Differing items:' not in result.stdout.str()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, maybe the test should make sure there is actually no second traceback (like reported in #44)?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea!

@The-Compiler

Copy link
Copy Markdown
Member

FWIW I don't really see a value in the warning. The monkeypatching is never something you'd enable explicitly, right? I'd imagine you either let it happen by default, or set mock_traceback_monkeypatch = false (Why does that option even exist? If something goes wrong with the patching?).

If I'm using --tb=native I'm already expecting longer/native/not-cleaned-up tracebacks, so it wouldn't surprise me at all if the monkeypatching doesn't take place. From the users perspective, if there wasn't #44, the patching wouldn't change anything in the output they see with --tb=native, right?

@nicoddemus

Copy link
Copy Markdown
Member Author

Note to self: mention this feature in README

@nicoddemus

Copy link
Copy Markdown
Member Author

FWIW I don't really see a value in the warning. The monkeypatching is never something you'd enable explicitly, right?

Hmm you got a point, it is enabled by default so the user won't "try to use it and it won't work", which I agree would be confusing. @blueyed perhaps a note on the README is enough?

Why does that option even exist? If something goes wrong with the patching?

I didn't know at the time if that monkeypatching could interfere with something else in more complex test suites, so I decided to put that option in there more like a preemptive measure.

@blueyed

blueyed commented Jun 1, 2016

Copy link
Copy Markdown
Contributor

@blueyed perhaps a note on the README is enough?

Would be fine with me.
My thinking was that a user might wonder why it does not work, enables it explicitly even, and then it still does not work. In the latter case a warning/note might be helpful, but could be easily overseen anyway.

@nicoddemus
nicoddemus merged commit dfd2603 into master Jun 1, 2016
@nicoddemus
nicoddemus deleted the 44-duplicated-traceback branch June 1, 2016 22:27
@nicoddemus

Copy link
Copy Markdown
Member Author

Thanks guys!

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.

4 participants