Skip to content
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

Don't use describe_to of mock objects #70

Merged
merged 1 commit into from Oct 29, 2018

Conversation

keis
Copy link
Contributor

@keis keis commented Jul 30, 2016

When using hamcrest together with mocks and asserting that the same mock objects are being passed around the assertion messages produce are bad because hamcrest ends up calling describe_to of the mocks which does nothing.

before

>>> from hamcrest import assert_that, equal_to
>>> from unittest.mock import Mock
>>> a,b = Mock(),Mock()
>>> assert_that(a, equal_to(b))
AssertionError: 
Expected: 
     but: was 

after

>>> from hamcrest import assert_that, equal_to
>>> from unittest.mock import Mock
>>> a,b = Mock(),Mock()
AssertionError: 
Expected: <Mock id='139861799912056'>
     but: was <Mock id='139861799911832'>

@coveralls
Copy link

coveralls commented Jul 30, 2016

Coverage Status

Coverage decreased (-0.2%) to 95.885% when pulling 6761d7f on keis:mock-description into 6b96955 on hamcrest:master.

@keis
Copy link
Contributor Author

keis commented Jul 30, 2016

Running in to some odd issues on travis

  • setuptools is not liking py32 any more by the looks of it (drop it?)
  • py3 docs is failing with an ImportError

@coveralls
Copy link

coveralls commented Jul 30, 2016

Coverage Status

Coverage decreased (-0.2%) to 95.885% when pulling 73b8c0d on keis:mock-description into 6b96955 on hamcrest:master.

@coveralls
Copy link

coveralls commented Jul 30, 2016

Coverage Status

Coverage decreased (-0.1%) to 95.758% when pulling 4096982 on keis:mock-description into c04a19e on hamcrest:master.

@das-g
Copy link

das-g commented Mar 2, 2018

Will this also work for unittest.mock.call objects? (See my StackOverflow question near-useless assertion output from hamcrest.contains_inanyorder applied to unittest.mock.Mock.mock_calls)

@Gnurfos
Copy link

Gnurfos commented Mar 2, 2018

Looking at the code, I don't think it will. I think _Call should be added to MOCKTYPES, and maybe _Sentinel as well. Unfortunately I failed to setup a pyhamcrest project in the short time I had, so I cannot contribute more for now.

@brunns
Copy link
Collaborator

brunns commented Oct 29, 2018

The build is working on Travis again now, so can you rebase this and try again @keis?

@keis
Copy link
Contributor Author

keis commented Oct 29, 2018

Completely forgot I had this PR open 😅

rebased!

@brunns
Copy link
Collaborator

brunns commented Oct 29, 2018

Thanks. Looks good to me, @offbyone.

The Call thing may be worth considering as a follow up, but this PR looks fine as it is.

@offbyone offbyone merged commit 20a0d72 into hamcrest:master Oct 29, 2018
@keis
Copy link
Contributor Author

keis commented Oct 29, 2018

Speaking of mock.Call the thing I was working when I ran into this was some custom matchers for Calls, may be of interest for some

https://github.com/keis/matchmock

@brunns
Copy link
Collaborator

brunns commented Oct 29, 2018

Hah - I've been working with something similar: https://github.com/brunns/brunns-matchers/blob/master/tests/unit/matchers/test_mock.py#L66

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.

None yet

6 participants