Skip to content

test_util: add (partial) testing for util.mount_cb#463

Merged
OddBloke merged 3 commits into
canonical:masterfrom
OddBloke:mount_cb
Jun 29, 2020
Merged

test_util: add (partial) testing for util.mount_cb#463
OddBloke merged 3 commits into
canonical:masterfrom
OddBloke:mount_cb

Conversation

@OddBloke
Copy link
Copy Markdown
Collaborator

No description provided.

Comment thread cloudinit/tests/test_util.py Outdated
def test_already_mounted_calls_callback(
self, already_mounted_device_and_mountdict, trailing_slash_in_mounts
):
device, mount_dict = already_mounted_device_and_mountdict
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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() 

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants