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

Refactored test_equals_none() function #78585

Closed
wants to merge 4 commits into from

Conversation

alexwholland
Copy link

SUMMARY

Removed equality statements in the test_equals_none() function since they are never used.

ISSUE TYPE
  • Bugfix Pull Request
COMPONENT NAME

test/units/inventory/test_host.py

@ansibot ansibot added affects_2.14 bug This issue/PR relates to a bug. core_review In order to be merged, this PR must follow the core review workflow. needs_triage Needs a first human triage before being processed. new_contributor This PR is the first contribution by a new community member. support:core This issue/PR relates to code supported by the Ansible Engineering Team. needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. and removed core_review In order to be merged, this PR must follow the core review workflow. labels Aug 18, 2022
@webknjaz
Copy link
Member

since they are never used.

Well, they may produce side effects. Have you checked that? What does the original commit say?

@webknjaz
Copy link
Member

Or maybe those lines are missing the assert statements, which is more likely. So I'd add the assertions instead of removing them.

@@ -69,10 +69,6 @@ def test_get_groups(self):

def test_equals_none(self):
other = None
self.hostA == other
Copy link
Member

Choose a reason for hiding this comment

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

@alikins can you recall what these were for?

@webknjaz
Copy link
Member

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@webknjaz
Copy link
Member

@mattclay I'm puzzled why this is happening under Python 3.9-3.11:

00:53 ==================================== ERRORS ====================================
00:53 ______________ ERROR collecting test/units/inventory/test_host.py ______________
00:53 ImportError while importing test module '/root/ansible/test/units/inventory/test_host.py'.
00:53 Hint: make sure your test modules/packages have valid Python names.
00:53 Traceback:
00:53 /usr/lib/python3.10/importlib/__init__.py:126: in import_module
00:53     return _bootstrap._gcd_import(name[level:], package, level)
00:53 test/units/inventory/test_host.py:25: in <module>
00:53     from units.compat import unittest
00:53 E   ModuleNotFoundError: No module named 'units'

I've restarted the jobs but the change doesn't seem to be caused by this patch 🤔.

@ansibot ansibot added core_review In order to be merged, this PR must follow the core review workflow. and removed needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. labels Aug 19, 2022
@alexwholland
Copy link
Author

since they are never used.

Well, they may produce side effects. Have you checked that? What does the original commit say?

Hi @webknjaz, as you probably saw the original commit #17827 for this test did not provide a reason for these equality statements, so I'm confused why these are here and causing the failed checks. I appreciate you looking into this issue.

@ansibot ansibot added needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. and removed core_review In order to be merged, this PR must follow the core review workflow. labels Aug 19, 2022
@webknjaz
Copy link
Member

so I'm confused why these are here and causing the failed checks.

I'm actually not sure your changes are causing this. Which is why I tagged @mattclay, so we could get to the bottom of this in case it's ansible-test being drunk.

If the changes were to cause this, my best guess is side effects caused by the dunder methods at https://github.com/ansible/ansible/blob/045f303/lib/ansible/inventory/host.py#L43. Although, I don't see anything that could actually cause a side effect there.
Besides, it fails way earlier any tests are being invoked. pytest fails on the test collection stage, which is when it just does the discovery of what's available on disk to compile the list of tests.

@webknjaz
Copy link
Member

@mattclay noticed that missing test/units/inventory/__init__.py is causing this

webknjaz added a commit to webknjaz/ansible that referenced this pull request Aug 19, 2022
Sometimes pytest errors out with an `ImportError` during its tests
collection stage when a Python package/directory containing the test
module does not have an `__init__.py` in it. This is being observed
under Python 3.9 and higher.

The patch provides a workaround for this problem but does not address
the root cause which is currently unknown.

Ref:
ansible#78585 (comment)
@webknjaz
Copy link
Member

This will fix it #78592

webknjaz added a commit that referenced this pull request Aug 19, 2022
Sometimes pytest errors out with an `ImportError` during its tests
collection stage when a Python package/directory containing the test
module does not have an `__init__.py` in it. This is being observed
under Python 3.9 and higher.

The patch provides a workaround for this problem but does not address
the root cause which is currently unknown.

Ref:
#78585 (comment)
webknjaz added a commit to webknjaz/ansible that referenced this pull request Aug 19, 2022
Sometimes pytest errors out with an `ImportError` during its tests
collection stage when a Python package/directory containing the test
module does not have an `__init__.py` in it. This is being observed
under Python 3.9 and higher.

The patch provides a workaround for this problem but does not address
the root cause which is currently unknown.

Ref:
ansible#78585 (comment)
(cherry picked from commit beb70da)
@ansibot ansibot added core_review In order to be merged, this PR must follow the core review workflow. and removed needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. labels Aug 19, 2022
@webknjaz
Copy link
Member

@alexwholland it's green now, but I'd still go for adding asserts instead of removing the lines.

webknjaz added a commit to webknjaz/ansible that referenced this pull request Aug 19, 2022
Sometimes pytest errors out with an `ImportError` during its tests
collection stage when a Python package/directory containing the test
module does not have an `__init__.py` in it. This is being observed
under Python 3.9 and higher.

The patch provides a workaround for this problem but does not address
the root cause which is currently unknown.

Ref:
ansible#78585 (comment)
(cherry picked from commit beb70da)
webknjaz added a commit to webknjaz/ansible that referenced this pull request Aug 19, 2022
Sometimes pytest errors out with an `ImportError` during its tests
collection stage when a Python package/directory containing the test
module does not have an `__init__.py` in it. This is being observed
under Python 3.9 and higher.

The patch provides a workaround for this problem but does not address
the root cause which is currently unknown.

Ref:
ansible#78585 (comment)
(cherry picked from commit beb70da)
@ansibot ansibot added needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. and removed core_review In order to be merged, this PR must follow the core review workflow. labels Aug 19, 2022
@webknjaz webknjaz added the ci_verified Changes made in this PR are causing tests to fail. label Aug 22, 2022
alexwholland and others added 2 commits August 22, 2022 09:50
Co-authored-by: Sviatoslav Sydorenko <wk.cvs.github@sydorenko.org.ua>
Co-authored-by: Sviatoslav Sydorenko <wk.cvs.github@sydorenko.org.ua>
@ansibot ansibot added core_review In order to be merged, this PR must follow the core review workflow. and removed ci_verified Changes made in this PR are causing tests to fail. needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. labels Aug 22, 2022
@s-hertel s-hertel removed the needs_triage Needs a first human triage before being processed. label Aug 23, 2022
sivel pushed a commit that referenced this pull request Aug 30, 2022
Sometimes pytest errors out with an `ImportError` during its tests
collection stage when a Python package/directory containing the test
module does not have an `__init__.py` in it. This is being observed
under Python 3.9 and higher.

The patch provides a workaround for this problem but does not address
the root cause which is currently unknown.

Ref:
#78585 (comment)
(cherry picked from commit beb70da)
@ansibot ansibot added the stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. label Aug 31, 2022
nitzmahone pushed a commit that referenced this pull request Aug 31, 2022
Sometimes pytest errors out with an `ImportError` during its tests
collection stage when a Python package/directory containing the test
module does not have an `__init__.py` in it. This is being observed
under Python 3.9 and higher.

The patch provides a workaround for this problem but does not address
the root cause which is currently unknown.

Ref:
#78585 (comment)
(cherry picked from commit beb70da)
nitzmahone pushed a commit that referenced this pull request Aug 31, 2022
Sometimes pytest errors out with an `ImportError` during its tests
collection stage when a Python package/directory containing the test
module does not have an `__init__.py` in it. This is being observed
under Python 3.9 and higher.

The patch provides a workaround for this problem but does not address
the root cause which is currently unknown.

Ref:
#78585 (comment)
(cherry picked from commit beb70da)
@ansibot ansibot added needs_rebase https://docs.ansible.com/ansible/devel/dev_guide/developing_rebasing.html needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. labels Feb 15, 2023
@mattclay
Copy link
Member

@alexwholland Thanks for submitting this PR. It looks like we forgot about this after the most recent changes were made. These fixes, along with other similar fixes, were merged as part of: #79940

@mattclay mattclay closed this Feb 16, 2023
@ansible ansible locked and limited conversation to collaborators Feb 23, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.14 bug This issue/PR relates to a bug. core_review In order to be merged, this PR must follow the core review workflow. needs_rebase https://docs.ansible.com/ansible/devel/dev_guide/developing_rebasing.html needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. new_contributor This PR is the first contribution by a new community member. stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. support:core This issue/PR relates to code supported by the Ansible Engineering Team.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants