Jack Sundberg

    Jack Sundberg

    1 year ago
    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
    Michael Adkins

    Michael Adkins

    1 year ago
    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
    Jack Sundberg

    Jack Sundberg

    1 year ago
    Thank you! This helps a bunch and I should be able to fix the tests now 🙂
    Michael Adkins

    Michael Adkins

    1 year ago
    Let me know if you have more questions about those!