Mityuha / fresh-bakery

Bake dependency injections asynchronously and stupidly simple
https://fresh-bakery.readthedocs.io/en/latest/
MIT License
21 stars 0 forks source link

Patch cakes with the Cake object only #41

Closed Mityuha closed 3 months ago

Mityuha commented 3 months ago

Now it's possible to patch attributes this way (from the docs):

async def test_example_3(bakery_mock: BakeryMock) -> None:
    bakery_mock.settings = lambda dsn: "any value"
    async with bakery_mock(MyBakery):
        assert MyBakery().settings == "any value"

As the practice show such a behaviour is an error prone and leads to confusion. There is a suggestion to get rid of any implicit behaviour in favour of explicit Cake objects' behaviour, like this

async def test_example_3(bakery_mock: BakeryMock) -> None:
    bakery_mock.settings = Cake(lambda dsn: "any value")
    async with bakery_mock(MyBakery):
        assert MyBakery().settings == "any value"
Mityuha commented 3 months ago

Implemented in 0.3.6 version