dimanche 1 novembre 2020

Use Pytest fixture with Flask-testing LiveServerTestCase

I am writing automated UI tests for my Flask app using Selenium and LiveServerTestCase from Flask testing.

This is how I have everything set up:

conftest.py

import pytest
from selenium import webdriver


@pytest.yield_fixture(scope="session")
def chrome_browser():
    browser = webdriver.Chrome()
    yield browser
    browser.quit()

test_main_page.py

from app import create_app
from flask_testing import LiveServerTestCase
import multiprocessing


class TestMainPage(LiveServerTestCase):
    multiprocessing.set_start_method("fork")

    def create_app(self):
        app = create_app()
        app.config['TESTING'] = True
        app.config.update(LIVESERVER_PORT=9898)
        return app

    def test_main_page(self, chrome_browser):
        driver = chrome_browser
        assert 1 == 1

Running Pytest giving me the following exception:

FAILED test_main_page.py::TestMainPage::test_main_page - TypeError: test_main_page() missing 1 required positional argument: 'chrome_browser'

When removing the LiveServerTestCase from the TestMainPage class, the fixture chrome_browser is working just fine.

How can I use both LiveServerTestCase and Pytest fixtures?

Thanks

Aucun commentaire:

Enregistrer un commentaire