Gotta catch up on mocking with at When I ask the bots to write unit tests, they...

@mistersql

Gotta catch up on mocking with at
When I ask the bots to write unit tests, they use ALL the mocking libraries,

The theme at the talk is mocking using `unittest` the built in way.

Self-replies

What's a good unit test?
- One assertion at at time -- eh, maybe.
- Independent/isolated/controlled <-- mocking's role
- Relevant/Meaningful <--- hard
- Repeatable/deterministic <-- also mocking's role
- Automatic <- CI all the things
- Descriptive <-- long names

Shadows on the wall parable ref! Mocks are the shadows on the wall.

What is I hear, is I should code in a cave.

Good practices
- minimize mocking
- use a library instead of your handrolled
- complex mocking means you should refactor

MagicMock means dict, list, str behavior* is mocked automatically. (Confusing why we would ever not use MagicMock)

* dunder methods

If the mock doesn't work
`@patch("library.thing")` then try
`@patch("my_code_where_i_import.library.library.thing")`

The other trick is to switch to
`import library as lib` instead of `from library import thing`

@patch autospec helps avoid mocking methods that don't exist. I think.

@patch Audience question: why/when use doctest? Simple scenarios.
Agreed.
Audience question: can you mock `self`?
me: don't mock yourself, it is bad for self-esteem.
me serious: sounds like how you'd test metaprogramming - I've never seen ordinary tests mock the `self`

@patch Audience question: Do mocks have use outside of unittesting?
speaker: maybe in an integration testing scenario with some bits mocked, e.g. a webserver with fake parts
me: Finding a mocking library outside of testing code would be astonishing. I'd want to see comments in such code to justify it.

@patch Audience question: how do I encourage the team to do unit tests?
speaker: unit testing something you can do now or you can do emergency app support at 3am
audience question: how do you know if you are mocking too much?
speaker: 2+ maybe
me: 5+, or if it is easy to use the real thing (file system is best example)