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

Cleanup test side effects #5074

Merged
merged 2 commits into from
Mar 20, 2024

Conversation

TheRealFalcon
Copy link
Member

Proposed Commit Message

See individual commits

Additional Context

Issues were found using a combination of
https://pypi.org/project/pytest-randomly/
and
https://pypi.org/project/pytest-bisect-tests/

Merge type

  • Squash merge using "Proposed Commit Message"
  • Rebase and merge unique commits. Requires commit messages per-commit each referencing the pull request number (#<PR_NUM>)

Copy link
Contributor

@aciba90 aciba90 left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks for this effort!

Do you think it is worth creating a scheduled GH action exercising pytest-randomly and pytest-bisect-tests?

@a-dubs
Copy link
Collaborator

a-dubs commented Mar 20, 2024

Do you think it is worth creating a scheduled GH action exercising pytest-randomly and pytest-bisect-tests?

I agree with @aciba90. Definitely does not need to be a PR action, but would be good to catch unit tests issues sooner.

@@ -763,7 +763,7 @@ def convert_net_json(network_json=None, known_macs=None):
cfg["type"] = "infiniband"

for service in services:
cfg = service
cfg = copy.deepcopy(service)
Copy link
Collaborator

@a-dubs a-dubs Mar 20, 2024

Choose a reason for hiding this comment

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

what necessitated this change and all the other deepcopy calls throughout the unit tests? just curious because I don't see how this related to leaked/failed mocks?

Copy link
Member Author

Choose a reason for hiding this comment

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

services is defined earlier as network_json.get("services", []) and network_json was directly passed into the function. That means that later in this loop when we do cfg.update({"type": "nameserver"}) that the passed in network_json gets modified inline.

This fixes that. While that is a bug in and of itself, it was found because we have tests that will pass the same networking config to this function, and so it was modified here in one test causing the test following it to fail.

Copy link
Member Author

@TheRealFalcon TheRealFalcon Mar 20, 2024

Choose a reason for hiding this comment

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

With the copy issues, it's not necessarily about mocks and instead about causing side effects that effect other tests. I updated the PR title to reflect this.

Copy link
Collaborator

Choose a reason for hiding this comment

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

thank you! that makes more sense now.

@TheRealFalcon TheRealFalcon changed the title Cleanup leaked mocks Cleanup test side effects Mar 20, 2024
@TheRealFalcon
Copy link
Member Author

Do you think it is worth creating a scheduled GH action exercising pytest-randomly and pytest-bisect-tests?

Yes, I'd like to have a daily that does that along with running unit tests on another platform to further ensure things are mocked enough.

Mocking doesn't work when we import functions directly.
These are the failures I could find when running tests in random order.
Changes that aren't self-explanatory should include a comment in the
test itself.

test_vultr.py includes a refactor to remove global state and remove
a test that didn't work and wasn't needed after the changes.
@TheRealFalcon TheRealFalcon merged commit 144782a into canonical:main Mar 20, 2024
26 of 28 checks passed
TheRealFalcon added a commit that referenced this pull request Mar 20, 2024
Mocking doesn't work when we import functions directly.
@TheRealFalcon TheRealFalcon deleted the cleanup-leaked-mocks branch March 20, 2024 19:48
blackboxsw pushed a commit to blackboxsw/cloud-init that referenced this pull request Apr 2, 2024
These are the failures I could find when running tests in random order.
Changes that aren't self-explanatory should include a comment in the
test itself.

test_vultr.py includes a refactor to remove global state and remove
a test that didn't work and wasn't needed after the changes.
@holmanb
Copy link
Member

holmanb commented Apr 2, 2024

Do you think it is worth creating a scheduled GH action exercising pytest-randomly and pytest-bisect-tests?

Yes, I'd like to have a daily that does that along with running unit tests on another platform to further ensure things are mocked enough.

@TheRealFalcon when you get a chance, I've proposed an Alpine ci PR for this.

blackboxsw pushed a commit to blackboxsw/cloud-init that referenced this pull request Apr 2, 2024
These are the failures I could find when running tests in random order.
Changes that aren't self-explanatory should include a comment in the
test itself.

test_vultr.py includes a refactor to remove global state and remove
a test that didn't work and wasn't needed after the changes.
blackboxsw pushed a commit to blackboxsw/cloud-init that referenced this pull request Apr 3, 2024
Mocking doesn't work when we import functions directly.
blackboxsw pushed a commit to blackboxsw/cloud-init that referenced this pull request Apr 3, 2024
These are the failures I could find when running tests in random order.
Changes that aren't self-explanatory should include a comment in the
test itself.

test_vultr.py includes a refactor to remove global state and remove
a test that didn't work and wasn't needed after the changes.
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.

4 participants