Skip to content
Preptima
mediumConceptCodingEntryMidSenior

Your test still reaches the network even though you patched the client. Talk me through fixture scope, parametrisation, and where a patch has to point.

4 min readUpdated 2026-08-15

Answer

Short answer

A patch must replace the name in the module under test, because a from-import binds its own reference that the original module never consults again. Fixture scope is a shared lifetime, parametrisation belongs on the inputs rather than the assertions, and coverage records execution, not verification.

Was this answer helpful?

Likely follow-ups

  • When would you use monkeypatch.setattr instead of unittest.mock.patch, and when the reverse?
  • What does autospec buy you, and what bug does a plain Mock let through?
  • How would you parametrise a case that is expected to fail without disabling the whole test?
  • Why can branch coverage fall while line coverage stays at a hundred percent?

Related questions

Further reading

Related Topics