Skip to content

Commit 6016876

Browse files
committed
Add a section about monkey-patching in tests to PRETTY_GOOD_PRACTICES.md.
1 parent a12df36 commit 6016876

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

PRETTY_GOOD_PRACTICES.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,13 @@ class SomeWallet:
619619
pytest does not.
620620
Our tests are fully dependent on pytest so there's no use in retaining `unittest` compatibility for this single point.
621621
Making a few tests `unittest` compatible is not useful compared with the cost of inconsistency.
622+
- Avoid monkey-patching (assigning to a method on a class object or instance)
623+
as much as possible, and if necessary, opt for it in an explicit and scoped
624+
manner using the `monkeypatch` fixture with a context manager, instead of
625+
silencing mypy using `# type: ignore[assignment]`.
626+
While in both cases we're signaling to the reader that something smelly/shady
627+
is going on, and type safety is lost, the monkeypatch approach with a context
628+
manager allows us to make the scope of the change controlled consistently.
622629

623630
## CLI
624631

0 commit comments

Comments
 (0)