Compare commits

...

2 Commits

Author SHA1 Message Date
Lila Yasin
6d665dda33 Fix awxkit tox test failure caused by root pytest.ini config bleed (#16520)
Forward-port of ansible/tower#7537 for the devel branch.

When running awxkit's tox tests, pytest picks up the root pytest.ini
which pulls in pytest-django options (--reuse-db, --nomigrations,
DJANGO_SETTINGS_MODULE) and Django-specific filterwarnings.  Since the
awxkit tox environment does not install Django or pytest-django, these
cause test collection to fail.

The root cause is that pytest.ini has absolute priority in pytest's
config discovery — it searches all ancestor directories for pytest.ini
before falling back to tox.ini's [pytest] section.  A [pytest] section
in awxkit/tox.ini alone cannot prevent the root config from being used.

Fix by:
- Adding awxkit/pytest.ini to act as the primary config boundary
  (pytest.ini has the highest priority in config discovery, so its
  presence in awxkit/ stops the upward search before reaching root)
- Adding explicit `test` path argument to the pytest command in
  awxkit/tox.ini so pytest discovers tests correctly
- Adding `testpaths` and `python_files` to the [pytest] section in
  awxkit/tox.ini as a secondary config boundary
- Adding awxkit/conftest.py that registers the Django-specific CLI
  options and INI keys as harmless no-ops, as a further safety net

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-06-24 10:42:23 -04:00
Stevenson Michel
17dc7f898a Fix: handle cursor-paginated responses in get_one() (#16521)
* Fix: handle cursor-paginated API responses in get_one()

DAB PR #1025 switched role_team_assignments and role_user_assignments
endpoints from PageNumberPagination to CursorPagination. Cursor
pagination returns {results, next, previous} without a count field,
causing get_one() to fail with "The endpoint did not provide count
and results".

When the response includes results but no count, infer count from
len(results). Also guard get_all_endpoint() against missing count.
2026-06-24 09:56:26 -04:00
4 changed files with 34 additions and 4 deletions

View File

@@ -438,7 +438,7 @@ class ControllerAPIModule(ControllerModule):
raise RuntimeError('Expected list from API at {0}, got: {1}'.format(endpoint, response))
next_page = response['json']['next']
if response['json']['count'] > 10000:
if response['json'].get('count', 0) > 10000:
self.fail_json(msg='The number of items being queried for is higher than 10,000.')
while next_page is not None:
@@ -493,8 +493,11 @@ class ControllerAPIModule(ControllerModule):
fail_msg += ', detail: {0}'.format(response['json']['detail'])
self.fail_json(msg=fail_msg)
if 'count' not in response['json'] or 'results' not in response['json']:
self.fail_json(msg="The endpoint did not provide count and results")
if 'results' not in response['json']:
self.fail_json(msg="The endpoint did not provide a results list")
if 'count' not in response['json']:
response['json']['count'] = len(response['json']['results'])
if response['json']['count'] == 0:
if allow_none:

16
awxkit/conftest.py Normal file
View File

@@ -0,0 +1,16 @@
# This conftest registers pytest-django CLI options and INI keys as harmless
# no-ops so that the awxkit tox environment (which does not install Django or
# pytest-django) does not crash when the root pytest.ini config leaks through.
#
# Root pytest.ini contains settings like --reuse-db, --nomigrations, and
# DJANGO_SETTINGS_MODULE that are only meaningful for Django tests. Placing
# this conftest at the awxkit/ level ensures it is loaded before argument
# parsing regardless of which config file pytest ultimately selects.
def pytest_addoption(parser):
group = parser.getgroup("awxkit-compat", "awxkit tox compatibility shims")
group.addoption("--reuse-db", action="store_true", default=False, help="(no-op in awxkit) pytest-django compat")
group.addoption("--nomigrations", action="store_true", default=False, help="(no-op in awxkit) pytest-django compat")
group.addoption("--create-db", action="store_true", default=False, help="(no-op in awxkit) pytest-django compat")
parser.addini("DJANGO_SETTINGS_MODULE", help="(no-op in awxkit) pytest-django compat", default="")

9
awxkit/pytest.ini Normal file
View File

@@ -0,0 +1,9 @@
[pytest]
addopts = -v --tb=native
testpaths = test
python_files = test_*.py
filterwarnings =
error
junit_family=xunit2

View File

@@ -19,7 +19,7 @@ deps =
pytest-mock
commands =
coverage run --parallel --source awxkit -m pytest --doctest-glob='*.md' --junit-xml=report.xml {posargs}
coverage run --parallel --source awxkit -m pytest -c pytest.ini test --doctest-glob='*.md' --junit-xml=report.xml {posargs}
coverage combine
coverage xml
@@ -44,6 +44,8 @@ max-line-length = 120
[pytest]
addopts = -v --tb=native
testpaths = test
python_files = test_*.py
filterwarnings =
error