Coverage for tests/conftest.py: 100%

33 statements  

« prev     ^ index     » next       coverage.py v7.8.0, created at 2025-05-05 14:02 +0000

1"""This file contains the fixtures for the tests.""" 

2 

3import logging 

4import os 

5import sys 

6import threading 

7from dotenv import load_dotenv 

8from selenium import webdriver 

9from selenium.webdriver.chrome.options import Options 

10import pytest 

11 

12SERVER_THREAD = None 

13 

14load_dotenv() 

15 

16os.environ["IS_TEST"] = "True" 

17 

18 

19@pytest.fixture(scope="session") 

20def flask_server(): 

21 """Start the Flask app in a separate thread.""" 

22 from app import app 

23 

24 # Set up logging to print to console 

25 logging.basicConfig(stream=sys.stdout, level=logging.DEBUG) 

26 

27 global SERVER_THREAD 

28 SERVER_THREAD = threading.Thread( 

29 target=lambda: app.run( 

30 port=5000, host="localhost", debug=False, use_reloader=False 

31 ) 

32 ) 

33 SERVER_THREAD.daemon = True 

34 SERVER_THREAD.start() 

35 yield 

36 # After the yield, kill the app 

37 

38 SERVER_THREAD.join(timeout=1) 

39 

40 

41@pytest.fixture() 

42def chrome_browser(): 

43 """Start a Chrome browser session.""" 

44 options = Options() 

45 options.add_argument("--headless") # Run Chrome in headless mode 

46 options.add_argument("--no-sandbox") 

47 options.add_argument("--disable-dev-shm-usage") 

48 options.add_argument("--disable-gpu") 

49 options.add_argument("--window-size=1280,800") 

50 

51 driver = webdriver.Chrome(options=options) 

52 

53 # Use this line instead if you wish to download the ChromeDriver binary on the fly 

54 # driver = webdriver.Chrome(service=ChromeService(ChromeDriverManager().install()), options=options) 

55 

56 driver.implicitly_wait(10) 

57 yield driver 

58 driver.delete_all_cookies() 

59 driver.quit()