https://prefect.io logo
Title
j

Jack Sundberg

02/22/2021, 2:05 AM
Hey everyone! I just opened a pull request and could use some help with updating a few CLI tests -- if anyone is able to help out, I would greatly appreciate it! https://github.com/PrefectHQ/prefect/pull/4146
💯 1
z

Zanie

02/22/2021, 4:52 PM
Hey @Jack Sundberg I can try to help explain a
MagicMock
at least. It's the same as a
Mock
but it has a few of the python built-ins implemented so it's easier to use, I wouldn't worry about that part. Basically you set some function that you're not interested in having actually run to a
MagicMock
e.g.
<http://http.Client.post|http.Client.post> = MagicMock()
now you can assert that the
post
method was called with some expected arguments without it actually hitting the internet, e.g.
http.Client.post.assert_called_once_with(url="<http://hello.com|hello.com>")
. It will also return mocks for attributes so for the example above we could have mocked
http.Client = MagicMock()
and (generally) still be able to assert calls on attributes
http.Client.post.assert...
As far as testing the CLI and capturing exceptions, a read of https://click.palletsprojects.com/en/7.x/testing/ will be helpful and perhaps https://click.palletsprojects.com/en/7.x/api/#click.testing.Result.exception
j

Jack Sundberg

02/22/2021, 5:08 PM
Thank you! This helps a bunch and I should be able to fix the tests now 🙂
z

Zanie

02/22/2021, 5:09 PM
Let me know if you have more questions about those!