Skip to content

Running Pytest2 locally is failing #1114

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
dabacon opened this issue Nov 6, 2018 · 3 comments
Closed

Running Pytest2 locally is failing #1114

dabacon opened this issue Nov 6, 2018 · 3 comments

Comments

@dabacon
Copy link
Collaborator

dabacon commented Nov 6, 2018

./continuious_integration/check.sh is failing on my and another developers box.  

____________________________ test_run_simulator_run ____________________________

    @mock.patch.multiple(cirq.SimulatesSamples, _run=mock.Mock())
    def test_run_simulator_run():
        simulator = cirq.SimulatesSamples()
        expected_measurements = {u'a': [[1]]}
        simulator._run.return_value = expected_measurements
        circuit = mock.Mock(cirq.Circuit)
        param_resolver = mock.Mock(cirq.ParamResolver)
        expected_result = cirq.TrialResult(repetitions=10,
                                           measurements=expected_measurements,
                                           params=param_resolver)
        assert expected_result == simulator.run(circuit=circuit,
                                                repetitions=10,
                                                param_resolver=param_resolver)
        simulator._run.assert_called_once_with(circuit=circuit,
                                               repetitions=10,
>                                              param_resolver=param_resolver)

cirq/sim/simulator_test.py:40: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

_mock_self = <Mock id='140181326865360'>, args = ()
kwargs = {'circuit': <Mock spec='Circuit' id='140181723293584'>, 'param_resolver': <Mock spec='ParamResolver' id='140181723291728'>, 'repetitions': 10}
self = <Mock id='140181326865360'>
msg = "Expected 'mock' to be called once. Called 2 times."

    def assert_called_once_with(_mock_self, *args, **kwargs):
        """assert that the mock was called exactly once and with the specified
        arguments."""
        self = _mock_self
        if not self.call_count == 1:
            msg = ("Expected '%s' to be called once. Called %s times." %
                   (self._mock_name or 'mock', self.call_count))
>           raise AssertionError(msg)
E           AssertionError: Expected 'mock' to be called once. Called 2 times.

.test_virtualenv_py2/local/lib/python2.7/site-packages/mock/mock.py:947: AssertionError
@Strilanc
Copy link
Contributor

Strilanc commented Nov 7, 2018

What version of python 2? python2 --version

@Strilanc
Copy link
Contributor

Strilanc commented Nov 7, 2018

I've managed to reproduce this. It's strange. It doesn't happen when you run ./check/pytest2, but it does for ./continuous_integration/check.sh. Also, it seems to have something to do with the tests running twice instead of once. I'm pretty sure the qubit sets not agreeing is due to the measurement being appended during the first run, then still being present during the second.

So, it appears that we're running into something analogous to the "do not use mutable values as default arguments", but in pytest itself?

For example, this:

@pytest.mark.parametrize(
    'x',
    [
        []
    ]
)
def test_random_same_matrix(x):
    x.append(1)
    assert x == [1]

Fails with this error:

E       assert [1, 1, 1] == [1]

I'll try to narrow down the exact set of things needed to make this happen. Current guess is "cache invalidation bug in pytest".

@Strilanc
Copy link
Contributor

Strilanc commented Nov 7, 2018

Figured it out. It's because of pytest-dev/pytest#4322 and also because the python 2 test checking code was using '' (which pytest interprets as 'run all tests') as a "no parameter" command line parameter instead of None.

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