This is a flask app with a rather simple pytest setup.
import subprocess
import time
import pytest
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
@pytest.fixture()
def start_flask_app():
# Start Flask server with coverage tracking so Selenium can interacts with it
server = subprocess.Popen(['coverage', 'run', '--source', 'server', '-m', 'flask', 'run'])
time.sleep(3) # Wait for the server to start
yield
server.terminate() # Stop the server after tests are done
@pytest.fixture()
def driver(start_flask_app):
options = Options()
options.add_argument('--headless')
options.add_argument('--disable-gpu')
driver = webdriver.Chrome(options=options)
yield driver
driver.close()
def test_health_page(driver):
"""
Test that health page works
"""
driver.get('http://localhost:5000/health')
assert 'UP' in driver.page_source
I runs test with pytest --cov=server
. Test cases pass. But my health route is not covered in the report.
Any idea why? Is this relevant? I tried to tweak my coveragerc but with no luck.
I am using
pytest==7.4.2
pytest-cov==4.1.0