From 86e83165d14c14dfbc8d899332acba2f89f91954 Mon Sep 17 00:00:00 2001 From: Jack Linke Date: Tue, 24 Oct 2023 16:11:31 -0400 Subject: [PATCH] Reflect parent project --- pyproject.toml | 2 ++ tests/test_with_docker_compose_playwright.py | 18 ++++++++++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 65bd3ab..3549c4a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -80,6 +80,8 @@ omit = ["tests/*", "**/migrations/*", "**/__init__.py"] [tool.pytest.ini_options] DJANGO_SETTINGS_MODULE = "tests.settings" python_files = ["*test_*.py", "*_test.py", "tests/*.py"] +log_cli = true +log_cli_level = "INFO" [tool.isort] profile = "black" diff --git a/tests/test_with_docker_compose_playwright.py b/tests/test_with_docker_compose_playwright.py index 0638ffc..a210c47 100644 --- a/tests/test_with_docker_compose_playwright.py +++ b/tests/test_with_docker_compose_playwright.py @@ -1,6 +1,7 @@ -"""This is a sample test for Playwright using Docker Compose.""" +"""This is a sample test for the Django app with Playwright using Docker Compose.""" import logging import re +import subprocess # nosec import pytest import requests @@ -19,21 +20,30 @@ def is_responsive(url): return False +def check_docker_ps(): + """Check if docker compose is running, and log the output using subprocess.Popen.""" + cmd = ["docker", "ps"] + proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) # nosec + stdout, stderr = proc.communicate() + logging.info(f"check_docker_ps return code: {proc.returncode}\noutput: {stdout}\nerrors: {stderr}") + + @pytest.fixture(scope="session") def http_service(docker_ip, docker_services): """Ensure that HTTP service is up and responsive.""" port = docker_services.port_for("django_test", 8000) url = f"http://{docker_ip}:{port}" - docker_services.wait_until_responsive(timeout=30.0, pause=0.1, check=lambda: is_responsive(url)) + logging.info(f"http_service url: {url}") + check_docker_ps() + docker_services.wait_until_responsive(timeout=60.0, pause=0.1, check=lambda: is_responsive(url)) return url def test_status_code(http_service): """Check the status code of the HTTP service.""" - logging.info(f"http_service: {http_service}") response = requests.get(http_service, timeout=60) - logging.info(f"response: {response}") + logging.info(f"test_status_code response: {response}") assert response.status_code == 200