Comment

Comment by simonw

Under "convention over configuration" is this bit:

> pytest also goes further and inspects the arguments to functions to figure out more things.

I think this pattern deserves its own category. I think of it as the Python world's variation on "dependency injection" and I really like it.

In pytest you can use argument names to request that specific test fixtures be made available to your test function: https://docs.pytest.org/en/6.2.x/fixture.html

I use it in Datasette to allow plugins to define their own view functions, which will be passed the specific objects that they declare a need for in order to process an incoming HTTP request: https://docs.datasette.io/en/stable/plugin_hooks.html#regist...

parent simonw 5 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton