Skip to content

Refactor container user test to use better helpers - #716

Merged
evgeni merged 1 commit into
theforeman:masterfrom
ekohl:clean-up-container-root-user-test
Jul 31, 2026
Merged

Refactor container user test to use better helpers#716
evgeni merged 1 commit into
theforeman:masterfrom
ekohl:clean-up-container-root-user-test

Conversation

@ekohl

@ekohl ekohl commented Jul 31, 2026

Copy link
Copy Markdown
Member

Why are you introducing these changes? (Problem description, related links)

In #711 (comment) it was pointed out this could be improved, which also made spot the possible testinfra improvement.

What are the changes introduced in this pull request?

This uses pytest's subtests to simplify the testing. It still reports each individual container that fails, but written in a cleaner way. Then uses testinfra's podman infrastructure to simplify it even further.

How to test this pull request

Steps to reproduce:

  • Run the test suite
  • Verify it still runs all the tests

Checklist

  • Tests added/updated (if applicable)
  • Documentation updated (if applicable)

Comment thread tests/container_user_test.py Outdated
Comment thread tests/container_user_test.py Outdated
@ekohl
ekohl force-pushed the clean-up-container-root-user-test branch from b6a329d to a10b89f Compare July 31, 2026 10:02
Comment thread tests/container_user_test.py Outdated
Comment thread tests/container_user_test.py Outdated
@ekohl
ekohl force-pushed the clean-up-container-root-user-test branch 2 times, most recently from bb61993 to bfdd756 Compare July 31, 2026 11:00
Comment thread tests/container_user_test.py Outdated
for container in containers:
with subtests.test(container.name):
user = container.inspect()['Config']['User']
if container.name in EXPECTED_ROOT_IMAGES:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
if container.name in EXPECTED_ROOT_IMAGES:
if container.inspect()['Config']['Image'] in EXPECTED_ROOT_IMAGES:

or we need to update the list to use names, but I think images is more representative

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Agreed, images are better. Only downside is that when we branch, we'll need to update nightly to the stable version but I think that is acceptable.

This uses pytest's subtests to simplify the testing. It still reports
each individual container that fails, but written in a cleaner way.
Then uses testinfra's podman infrastructure to simplify it even further.

Link: https://docs.pytest.org/en/stable/how-to/subtests.html
Link: https://testinfra.readthedocs.io/en/latest/modules.html#testinfra.modules.podman.Podman.get_containers
@ekohl
ekohl force-pushed the clean-up-container-root-user-test branch from bfdd756 to b719e69 Compare July 31, 2026 11:53
@evgeni
evgeni enabled auto-merge (rebase) July 31, 2026 12:08
@evgeni
evgeni merged commit e7fab36 into theforeman:master Jul 31, 2026
16 checks passed
@ekohl
ekohl deleted the clean-up-container-root-user-test branch July 31, 2026 21:19
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