N
N
npa5552016-04-10 20:05:13
Automation
npa555, 2016-04-10 20:05:13

How to import fixture into a test?

Good time of the day. There is a test (using selenium) - checking the addition of goods to the cart. Created a separate selenium_fixture file that would open and close the browser:
from selenium import webdriver
import pytest
@pytest.fixture
def driver(request):
driver = webdriver.Firefox()
driver.implicitly_wait(10)
request.addfinalizer(driver.quit)
return (driver)
In the test itself I write from selenium_fixture import driver, but for some reason it is not imported. I'm doing it in the pycharm development environment. Added the pytest library to the environment. Also, in the settings in the Python integrated tools section, I set py.test in the Default test runner field. All the same, the test does not run, the module is not imported.
Tell me what it can be, what I'm doing wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
voloxastik, 2019-04-22
@voloxastik

Move the fixture to the conftest.py file. The fixtures in this file are applied automatically.

@pytest.fixture(scope="session")
def driver(request):
   driver = webdriver.Firefox()
   driver.implicitly_wait(10)
   request.addfinalizer(driver.quit)
   return(driver)

The test file must start or end with test.
And the name of the test must also begin or end with test.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question