Getting AttributeError: module 'pytest' has no attribute 'main' error while executing the script | Selenium Python Forum
poornima Posted on 29/03/2020

Showing uo below error message after running the pytest code.

Traceback (most recent call last):
  File "C:\Eclipse\eclipse\plugins\org.python.pydev.core_7.5.0.202001101138\pysrc\", line 273, in <module>
  File "C:\Eclipse\eclipse\plugins\org.python.pydev.core_7.5.0.202001101138\pysrc\", line 265, in main
    return pytest.main(argv)
AttributeError: module 'pytest' has no attribute 'main'

Python version: 3.7.4

Pytest Version: 5.4.1


def test_first():
driver=webdriver.Chrome(executable_path=path) #from where need to execute the path #
# driver=webdriver.Chrome()
driver.implicitly_wait(10) # It will wait till the browser and the url is loaded. Take the time is sec#
time.sleep(3) #import time package to check the browser is completely opened#

Jaspreet Replied on 02/04/2020


Please make sure you make the following checks: 

1. The test runner is py.test while running the test.

2. The location of the driver is properly given. 

3. The package name and module name starts with test.

4. While creating package there is a file named '' is not modified and is lying in the same package.

5. Run the test case as Python Unit-test


Still if the issue is coming for main, delete the package and recreate it

Kam Replied on 18/05/2020

I am getting error even though I dont have any of above conditions. when I add new key word it starts to dispaly error. Also Test case stops, and no report is generated. There is some other reasons?

Jaspreet Replied on 19/05/2020


The error who are facing can be result of different version of pytest. Please try using older version of pytest by unistalling it from cm using the command "pip uninstall pytest" and installing the older version again and try running the code.

Related Posts