mirror of
https://github.com/ansible/awx.git
synced 2026-01-28 00:51:27 -03:30
In essence, this configures Python to turn any warnings emitted in
runtime into errors[[1]]. This is the best practice that allows
reacting to future deprecation announcements that are coming from the
dependencies (direct, or transitive, or even CPython itself)[[2]].
The typical workflow looks like this:
1. If a dependency is updated an a warning is hit in tests, the
deprecated thing should be replaced with newer APIs.
2. If a dependency is transitive or we have no control over it
otherwise, the specific warning and a regex matching its message,
plus the module reference (where possible) can be added to the
list of temporary ignores in `pytest.ini`.
3. The list of temporary ignores should be reevaluated periodically,
including when dependency re-pinning in lockfile is happening.
[1]: https://docs.python.org/3/using/cmdline.html#cmdoption-W
[2]: https://pytest-with-eric.com/configuration/pytest-ignore-warnings/
53 lines
1.6 KiB
Python
53 lines
1.6 KiB
Python
from __future__ import absolute_import, division, print_function
|
|
|
|
__metaclass__ = type
|
|
|
|
import pytest
|
|
|
|
from awx.main.models import Instance
|
|
from django.test.utils import override_settings
|
|
|
|
|
|
@pytest.mark.filterwarnings(
|
|
# FIXME: Figure out where it is emited and what causes it.
|
|
# FIXME: The suppression should be made more specific or the cause fixed.
|
|
# Ref: https://github.com/ansible/awx/pull/15620
|
|
"ignore::RuntimeWarning",
|
|
)
|
|
@pytest.mark.django_db
|
|
def test_peers_adding_and_removing(run_module, admin_user):
|
|
with override_settings(IS_K8S=True):
|
|
result = run_module(
|
|
'instance',
|
|
{'hostname': 'hopnode', 'node_type': 'hop', 'node_state': 'installed', 'listener_port': 6789},
|
|
admin_user,
|
|
)
|
|
assert result['changed']
|
|
|
|
hop_node = Instance.objects.get(pk=result.get('id'))
|
|
|
|
assert hop_node.node_type == 'hop'
|
|
|
|
address = hop_node.receptor_addresses.get(pk=result.get('id'))
|
|
assert address.port == 6789
|
|
|
|
result = run_module(
|
|
'instance',
|
|
{'hostname': 'executionnode', 'node_type': 'execution', 'node_state': 'installed', 'peers': ['hopnode']},
|
|
admin_user,
|
|
)
|
|
assert result['changed']
|
|
|
|
execution_node = Instance.objects.get(pk=result.get('id'))
|
|
|
|
assert set(execution_node.peers.all()) == {address}
|
|
|
|
result = run_module(
|
|
'instance',
|
|
{'hostname': 'executionnode', 'node_type': 'execution', 'node_state': 'installed', 'peers': []},
|
|
admin_user,
|
|
)
|
|
|
|
assert result['changed']
|
|
assert set(execution_node.peers.all()) == set()
|