3

When I run the below code with

pytest .\tests\GET\test_setupFunc.py

it works perfectly i.e. setup(my_fixture) function run once then test_one and test_two

if i run it parallely using pytest-xdist using this

pytest .\tests\GET\test_setupFunc.py -n=2

it fails

i think my_fixture is being called by both test since i have setup the scope="session" that function should be shared.

once that function is run successfully, I want parallelism should get trigger

========== short test summary info =========

ERROR tests\GET\test_setupFunc.py::test_one - selenium.common.exceptions.WebDriverException: Message: unknown error: Could not remove old devtools port file. Perhaps t...

please do replace yourusername with your username of system in addarguement code step in case you plan to run it

'''

import pytest
import logging
logging.basicConfig(format='%(message)s')

from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager

@pytest.fixture(autouse=True, scope='session')
def my_fixture():
   logging.warning('setup function')
   print(" i will be called only once i am one time")
   options = webdriver.ChromeOptions() 
   options.add_argument('--profile-directory=Default')
   options.add_argument("--user-data-dir=c:\\Users\\yourUserName\\AppData\\Local\\Google\\Chrome\\User Data")
   driver=webdriver.Chrome(ChromeDriverManager().install(), options=options)
   driver.get("https://gmail.com")
   
   driver.quit()

def test_one():
    logging.warning('test_a')

    print(" i am first function")

def test_two():
    logging.warning('test_b')
    print(" i am second function")

Also to note if I remove selenium related steps and just keep print statements it works fine

Expected Result

  1. setup method is called once 2 methods should be called once setup ran successfully once

pytest-parallel does not support python 3.9 yet tried that as well

Gaurav Khurana
  • 3,423
  • 2
  • 29
  • 38

0 Answers0