Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix test warnings and errors under pytest #167

Merged
merged 3 commits into from
Jul 19, 2024
Merged

Conversation

larsks
Copy link
Member

@larsks larsks commented Jul 19, 2024

This is prep work for adding some integration tests to this repository. I would like to be able to use pytest fixtures as part of the integration tests, but in order to do that we need to ensure that the existing tests run cleanly under pytest.

I tried running the test suite using pytest, and while it mostly works, there were a number of errors and warnings that cropped up. Primarily:

  1. We need to catch exceptions in threads spawned during the test process.

  2. We need to pass valid UUIDs to anything expecting a UUID; failure to do so yields a warning. So many warnings.

With this pull request, all tests run cleanly under pytest. There are still warnings, but they all come from third party modules and so are somebody else's problem.

larsks added 2 commits July 19, 2024 12:08
I tried running the test suite using pytest, and while it mostly works,
there were a number of errors and warnings that cropped up. Primarily:

1. We need to catch exceptions in threads spawned during the test process.

2. We need to pass valid UUIDs to anything expecting a UUID; failure to do
    so yields a warning. So many warnings.

With this commit, the tests -- with the exception of
TestRequestContextSerializer -- run cleanly under pytest. There are still
warnings, but they all come from third party modules and so are somebody
else's problem.

The issues with TestRequestContextSerializer are resolved in the
following commit.
Use mock.patch to mock out `rpc.TestRequestContextSerializer` instead of an
explicit assignment statement. Doing something like this in a test...

    rpc.RequestContextSerializer = mock.Mock()

...has side effects for any subsequent tests that rely on
`rpc.RequestContextSerializer`. Using `mock.patch` ensures that the
original value is replaced when the test is complete so that other tests
can use the original code.
@larsks larsks requested review from tzumainn and DanNiESh July 19, 2024 16:11
@larsks larsks self-assigned this Jul 19, 2024
Classes that start with `Test` are identified as test cases, causing
warnings during test discovery. In this commit we rename `TestNode` to
`FakeNode` to prevent it from being erroneously collected as a test.
Copy link
Contributor

@tzumainn tzumainn left a comment

Choose a reason for hiding this comment

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

Looks good to me - thanks!

@larsks larsks merged commit 92922ca into CCI-MOC:master Jul 19, 2024
6 checks passed
@larsks larsks deleted the fix/tests branch July 19, 2024 20:01
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