Skip to content

Commit

Permalink
Add a section about monkey-patching in tests to PRETTY_GOOD_PRACTICES…
Browse files Browse the repository at this point in the history
….md.
  • Loading branch information
AmineKhaldi committed Dec 16, 2024
1 parent a12df36 commit 6e0cfbf
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions PRETTY_GOOD_PRACTICES.md
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,9 @@ class SomeWallet:
pytest does not.
Our tests are fully dependent on pytest so there's no use in retaining `unittest` compatibility for this single point.
Making a few tests `unittest` compatible is not useful compared with the cost of inconsistency.
- Avoid monkey-patching (assigning to a method on a class object or instance) as much as possible.
If necessary, opt for it in an explicit and scoped manner using the `monkeypatch: pytest.MonkeyPatch` fixture with a context manager, instead of silencing mypy using `# type: ignore[assignment]`.
While in both cases we're signaling to the reader that something smelly/shady is going on, and type safety is lost, the monkeypatch approach with a context manager allows us to make the scope of the change controlled consistently.

## CLI

Expand Down

0 comments on commit 6e0cfbf

Please sign in to comment.