Skip to content

Container PyTest for Nginx-container#346

Merged
phracek merged 4 commits intomasterfrom
container_pytests
Oct 17, 2025
Merged

Container PyTest for Nginx-container#346
phracek merged 4 commits intomasterfrom
container_pytests

Conversation

@phracek
Copy link
Member

@phracek phracek commented Sep 11, 2025

This pull request contains set of PyTest from migration bash tests to PyTest.

The migration matrix is:

TEST_LIST_APP="\
test_s2i_usage -> test_container_basics.py(TestNginxContainer.test_run_s2i_usage)
test_docker_run_usage -> test_container_basics.py(TestNginxContainer.test_docker_run_usage)
test_scl_usage -> test_container_basics.py(TestNginxContainer.test_scl_usage)
test_application -> test_container_application.py(TestNginxApplicationContainer.test_application)
test_log_output -> test_container_log.py(TestNginxLogContainer.test_log_output)
test_log_volume_output -> test_container_log.py(TestNginxLogContainer.test_log_volume_output)
test_application_user ->  test_container_application.py(TestNginxApplicationContainer.test_application_user)
"
TEST_LIST_HOOK_APP="test_pre_init_script" -> test_container_example_app.py(TestNginxExampleAppContainer.test_run_app_test)
TEST_LIST_PERL_APP="test_perl_directive" -> test_container_example_app.py(TestNginxExamplePerlAppContainer.test_run_app_test)
TEST_LIST_MISC=run_dockerfiles_test -> test_container_basics.py(TestNginxContainer.test_dockerfiles)

Also OpenShift Pytest were renamed to test_ocp_*.py

@phracek phracek force-pushed the container_pytests branch 3 times, most recently from 6d1b8be to a9b364b Compare September 11, 2025 13:54
@phracek
Copy link
Member Author

phracek commented Sep 11, 2025

[test-pytest]

@github-actions
Copy link

github-actions bot commented Sep 11, 2025

Pull Request validation

Failed

🔴 Failed or pending statuses:

  • Testing Farm - RHEL8 - OpenShift 4 - 1.22[pending]
  • Testing Farm - RHEL8 - PyTest - 1.24[pending]
  • Testing Farm - RHEL10 - PyTest - 1.26[pending]
  • Testing Farm - RHEL8 - OpenShift 4 - 1.24[pending]
  • Testing Farm - RHEL10 - OpenShift 4 - 1.26[pending]
  • Testing Farm - RHEL8 - OpenShift 4 - 1.22-micro[pending]
  • Testing Farm - RHEL9 - PyTest - 1.24[pending]

🔴 Review - Missing review from a member (1 required)

@github-actions
Copy link

github-actions bot commented Sep 11, 2025

Testing Farm results

namecomposearchstatusstarted (UTC)timelogs
Fedora - PyTest - 1.26Fedora-latestx86_64✅ passed16.10.2025 11:10:566min 53stest pipeline
CentOS Stream 10 - PyTest - 1.26CentOS-Stream-10x86_64✅ passed16.10.2025 11:31:228min 45stest pipeline
CentOS Stream 9 - PyTest - 1.24CentOS-Stream-9x86_64✅ passed16.10.2025 10:54:1210min 3stest pipeline
CentOS Stream 9 - PyTest - 1.22-microCentOS-Stream-9x86_64✅ passed16.10.2025 11:46:499min 42stest pipeline
CentOS Stream 9 - PyTest - 1.26CentOS-Stream-9x86_64✅ passed16.10.2025 11:46:398min 47stest pipeline
RHEL10 - PyTest - 1.26RHEL-10-Nightlyx86_64✅ passed16.10.2025 11:01:3111min 55stest pipeline
RHEL8 - PyTest - 1.22RHEL-8.10.0-Nightlyx86_64✅ passed16.10.2025 11:48:5914min 27stest pipeline
RHEL8 - PyTest - 1.22-microRHEL-8.10.0-Nightlyx86_64✅ passed16.10.2025 11:32:2617min 19stest pipeline
RHEL8 - PyTest - 1.24RHEL-8.10.0-Nightlyx86_64✅ passed16.10.2025 11:00:2214min 43stest pipeline
RHEL9 - Unsubscribed host - 1.26RHEL-9.6.0-Nightlyx86_64✅ passed11.09.2025 13:55:1217min 39stest pipeline
RHEL9 - Unsubscribed host - 1.20RHEL-9.6.0-Nightlyx86_64✅ passed11.09.2025 13:55:1817min 18stest pipeline
RHEL9 - PyTest - 1.22RHEL-9.6.0-Nightlyx86_64✅ passed16.10.2025 11:35:0119min 4stest pipeline
RHEL9 - Unsubscribed host - 1.22RHEL-9.6.0-Nightlyx86_64✅ passed11.09.2025 13:56:3316min 49stest pipeline
RHEL9 - PyTest - 1.24RHEL-9.6.0-Nightlyx86_64✅ passed16.10.2025 11:06:5416min 18stest pipeline
RHEL9 - PyTest - 1.20RHEL-9.6.0-Nightlyx86_64✅ passed16.10.2025 11:42:0316min 21stest pipeline
RHEL9 - PyTest - 1.26RHEL-9.6.0-Nightlyx86_64✅ passed16.10.2025 11:38:1016min 34stest pipeline
RHEL9 - Unsubscribed host - PyTest - 1.20RHEL-9.6.0-Nightlyx86_64✅ passed16.10.2025 11:35:2016min 30stest pipeline
RHEL9 - Unsubscribed host - PyTest - 1.24RHEL-9.6.0-Nightlyx86_64✅ passed16.10.2025 11:13:5415min 41stest pipeline
RHEL9 - Unsubscribed host - PyTest - 1.26RHEL-9.6.0-Nightlyx86_64✅ passed16.10.2025 11:53:3016min 13stest pipeline
RHEL9 - Unsubscribed host - PyTest - 1.22RHEL-9.6.0-Nightlyx86_64✅ passed16.10.2025 11:40:0715min 2stest pipeline
RHEL10 - OpenShift 4 - 1.26RHEL-10-Nightlyx86_64✅ passed16.10.2025 11:03:5318min 18stest pipeline
RHEL8 - OpenShift 4 - 1.22RHEL-8.10.0-Nightlyx86_64✅ passed16.10.2025 11:00:2120min 41stest pipeline
RHEL9 - OpenShift 4 - 1.22RHEL-9.6.0-Nightlyx86_64✅ passed16.10.2025 11:08:4121min 38stest pipeline
RHEL9 - OpenShift 4 - 1.20RHEL-9.6.0-Nightlyx86_64✅ passed16.10.2025 11:10:5521min 49stest pipeline
RHEL8 - OpenShift 4 - 1.22-microRHEL-8.10.0-Nightlyx86_64✅ passed16.10.2025 11:04:0021min 52stest pipeline
RHEL8 - OpenShift 4 - 1.24RHEL-8.10.0-Nightlyx86_64✅ passed16.10.2025 11:01:4120min 57stest pipeline
RHEL9 - OpenShift 4 - 1.24RHEL-9.6.0-Nightlyx86_64✅ passed16.10.2025 11:33:2025min 57stest pipeline
RHEL9 - OpenShift 4 - 1.26RHEL-9.6.0-Nightlyx86_64✅ passed16.10.2025 11:36:2322min 24stest pipeline

@phracek
Copy link
Member Author

phracek commented Sep 16, 2025

[test-pytest]

@phracek
Copy link
Member Author

phracek commented Sep 16, 2025

Let's test it again after fixing VERSION and micro

[test-pytest]

@phracek
Copy link
Member Author

phracek commented Sep 16, 2025

/auto-merge

@phracek
Copy link
Member Author

phracek commented Sep 19, 2025

[test-pytest]

@phracek
Copy link
Member Author

phracek commented Oct 7, 2025

$ pre-commit run --config ~/.pre-commit-config.yaml --files test/test_container_application.py test/test_container_basics.py test/test_container_example_apps.py
Check for added large files..............................................Passed
Check for merge conflicts................................................Passed
Check python ast.........................................................Passed
Check Yaml...........................................(no files to check)Skipped
Detect Private Key.......................................................Passed
Fix End of Files.........................................................Passed
Trim Trailing Whitespace.................................................Passed
Flake8...................................................................Passed
mypy.....................................................................Passed

@phracek
Copy link
Member Author

phracek commented Oct 7, 2025

[test-pytest]

@phracek
Copy link
Member Author

phracek commented Oct 7, 2025

After removing some leftovers, let's test it again.
[test-pytest]

@phracek
Copy link
Member Author

phracek commented Oct 8, 2025

[test-pytest]

Signed-off-by: Petr "Stone" Hracek <phracek@redhat.com>
All PyTest have naming `test_container_*.py`

Signed-off-by: Petr "Stone" Hracek <phracek@redhat.com>
@phracek
Copy link
Member Author

phracek commented Oct 14, 2025

The suite were completelly rewritten based on s2i-python-container improvements sclorg/s2i-python-container#759

[test-pytest][test-openshift]

Fix pre-commit issues

Signed-off-by: Petr "Stone" Hracek <phracek@redhat.com>
@phracek
Copy link
Member Author

phracek commented Oct 15, 2025

@frenzymadness The tests have been rewritten based on your small improvements in s2i-python-container.
Similar like s2i-perl-container.

All was also checked by pre-commit scripts. So it should be easy to review.

So PTAL. Not urgent.

@phracek
Copy link
Member Author

phracek commented Oct 15, 2025

[test-pytest][test-openshift]

Signed-off-by: Petr "Stone" Hracek <phracek@redhat.com>
@phracek
Copy link
Member Author

phracek commented Oct 16, 2025

[test-pytest][test-openshift]

@phracek phracek requested a review from frenzymadness October 17, 2025 07:19
Copy link
Member

@frenzymadness frenzymadness left a comment

Choose a reason for hiding this comment

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

It's good overall. I found just a few possible improvements.


THISDIR=$(dirname ${BASH_SOURCE[0]})

git show -s
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure what this is good for. The information about the last commit is usually available in the CI, and you typically don't need it in the output.

Comment on lines +53 to +59
command = PodmanCLIWrapper.podman_get_file_content(
cid_file_name=cid, filename="/opt/app-root/etc/nginx.d/default.conf"
)
# Checks if nginx configuration contains resolver
assert re.search("resolver", command)
# Checks if nginx configuration DO NOT container "DNS_SERVER"
assert not re.search("DNS_SERVER", command)
Copy link
Member

Choose a reason for hiding this comment

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

command is not a very good descriptive name for this variable.

Suggested change
command = PodmanCLIWrapper.podman_get_file_content(
cid_file_name=cid, filename="/opt/app-root/etc/nginx.d/default.conf"
)
# Checks if nginx configuration contains resolver
assert re.search("resolver", command)
# Checks if nginx configuration DO NOT container "DNS_SERVER"
assert not re.search("DNS_SERVER", command)
nginx_config = PodmanCLIWrapper.podman_get_file_content(
cid_file_name=cid, filename="/opt/app-root/etc/nginx.d/default.conf"
)
# Checks if nginx configuration contains resolver
assert re.search("resolver", nginx_config)
# Checks if nginx configuration DO NOT container "DNS_SERVER"
assert not re.search("DNS_SERVER", nginx_config)


def test_run_app_test(self):
if VARS.VERSION.endswith("-micro"):
pytest.skip("Run the chosen tests (not for micro variant which lacks perl)")
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
pytest.skip("Run the chosen tests (not for micro variant which lacks perl)")
pytest.skip("Micro image variant lacks Perl.")

url=f"http://{cip}", port=8080, page="/nothing-at-all", expected_code=404
)
logs = self.s2i_app.get_logs(cid_file_name=cid_file_name)
assert logs
Copy link
Member

Choose a reason for hiding this comment

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

This is kinda duplicate. If logs is empty, the next assert fails because it won't find anything in an empty string.

class TestLatestImagestreams:

def setup_method(self):
self.isc = ImageStreamChecker(working_dir=VARS.TEST_DIR / ".." / "..")
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
self.isc = ImageStreamChecker(working_dir=VARS.TEST_DIR / ".." / "..")
self.isc = ImageStreamChecker(working_dir=VARS.TEST_DIR.parent.parent)

Test checks we have the latest imagestream in GitHub repository
"""
self.latest_version = self.isc.get_latest_version()
assert self.latest_version != ""
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
assert self.latest_version != ""
assert self.latest_version

@phracek phracek merged commit 30885ea into master Oct 17, 2025
27 checks passed
@phracek phracek deleted the container_pytests branch October 17, 2025 07:31
phracek added a commit that referenced this pull request Oct 17, 2025
#346

Signed-off-by: Petr "Stone" Hracek <phracek@redhat.com>
phracek added a commit that referenced this pull request Oct 17, 2025
#346

Signed-off-by: Petr "Stone" Hracek <phracek@redhat.com>
phracek added a commit that referenced this pull request Oct 20, 2025
#346

Signed-off-by: Petr "Stone" Hracek <phracek@redhat.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants