test_util: add (partial) testing for util.mount_cb#463
Conversation
| def test_already_mounted_calls_callback( | ||
| self, already_mounted_device_and_mountdict, trailing_slash_in_mounts | ||
| ): | ||
| device, mount_dict = already_mounted_device_and_mountdict |
There was a problem hiding this comment.
I get that this is an arg in the test and it's a generator so is mock doing the functional calling? I was expecting this to end with parens but perhaps that's handled in the pytest tooling?
device, mount_dict = already_mounted_device_and_mountdict()
There was a problem hiding this comment.
already_mounted_device_and_mountdict is a pytest fixture, specifically the one defined on line 718 in this file (and within this class). We yield a tuple there, which pytest passes in as the fixture argument (it will have first run everything up to the yield; it runs the remainder of the fixture once the test is complete, for tear-down).
If fixtures always required calling, then any tests which need to use the passed value in more than one place would end up with an additional fixture_name = fixture_name() at the top.
Note that you can have fixtures return callables: ubuntu-advantage-client's conftest.py has a couple of examples (caplog_text returns _func, FakeConfig returns a class/type object), and pytest ships the tmpdir_factory fixture.
(As a side note: I realised that this method definition isn't following the parameter order guidelines that we have laid out in HACKING.md, so I've also reversed their order.)
No description provided.