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

Fix a flaky test by cleaning a polluted state. #33

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

sturmianseq
Copy link

What is the purpose of the change

This PR is to fix a flaky test tests/test_api_client.py::TestApiClient::test_authentication_error, which can fail after running tests/test_api_client.py::TestApiClient::test_param_required_error, but passes when it is run in isolation.

Reproduce the test failure

Run the following command:

python -m pytest tests/test_api_client.py::TestApiClient::test_param_required_error tests/test_api_client.py::TestApiClient::test_authentication_error

Expected result

Test tests/test_api_client.py::TestApiClient::test_authentication_error should pass when it is run after test tests/test_api_client.py::TestApiClient::test_param_required_error.

Actual result

Test tests/test_api_client.py::TestApiClient::test_authentication_error fails:

   def _proceed_response(self, response):
        if not response.ok:
>           raise build_api_error(response)
E           coinbase_commerce.error.ParamRequiredError: Request id <MagicMock name='mock.get().headers.get()' id='140023001166560'>: <empty message>

coinbase_commerce/client.py:89: ParamRequiredError

Why the test fails

The error return value of mock.MagicMock.content is polluted after tests/test_api_client.py::TestApiClient::test_param_required_error.

Fix

Reset mock.MagicMock.content at the start of tests/test_api_client.py::TestApiClient::test_authentication_error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

1 participant