-
-
Notifications
You must be signed in to change notification settings - Fork 353
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
Passthrus persist accross tests #322
Comments
I believe this is a big deal. One of the key principle in (unit) testing is test isolation. What's worse, according to my testing all mocked responses persist across tests, so it totally breaks test isolation and makes the overall result depend on test execution order 👎 |
@knaperek stop parroting unit testing insanity. This lib is obviously for integration testing. Which mean testing some state and state means no isolation. If you need this for your 'unit' tests, then you are doing somethign wrong. your unit tests should be isolated from any http stuff. its the D in SOLID. |
The "unit" was intentionally enclosed with parenthesis, you can totally leave it out if it helps your understanding. The distinction between unit and integration (or other) types of tests is irrelevant in this context though. Test isolation is a very important aspect of any type of automated tests. The need to preserve state in an integration test only lasts until that test completes (successfully or not). You certainly don't want that state to leak into other tests that are being executed in the same test run as a part of the same (or different) test suite. The problem that I observed with this library is that fake responses defined for one test leak into other tests as well. That's a bugger, because it breaks test isolation, which in turn breaks determinism and independence on the order of execution. I believe you want to have your integration test results independent on their order of execution, right? |
nah. I'm trying to do lifecycle stuff. |
My case is even worse, the mocked responses are leaking into tests that aren't decorated with UPDATE: I've figured out what was causing this, I had functions wrapped in @responses.activate calling other such decorated functions. Removing the innermost decorators solved the problem. |
Hello, I just ran into what I believe is a bug. Calls to
responses.add_passthru
persist across tests. This wouldn't be a big deal except running tests in a random order causes failures.This works:
This fails:
In the failing example you can see that since we called
responses.add_passthru
in the first test case, the second test case fails because the passthru is still active.Even though the passthru is still active, calling
responses.passthru_prefixes
returns an empty tuple but callingresponses._default_mock.passthru_prefixes
returns something different.I think this is due to how it is assigned in the code. You are assigning a value, not a reference to_default_mock.passthru_prefixes
but that's a quick guess without looking into the code too deep.The text was updated successfully, but these errors were encountered: