Getting AttributeError: module 'pytest' has no attribute 'main' error while executing the script | Selenium Python Forum
P
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\runfiles.py", line 273, in <module>
    main()
  File "C:\Eclipse\eclipse\plugins\org.python.pydev.core_7.5.0.202001101138\pysrc\runfiles.py", 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

code:

def test_first():
path="C:\\Users\\lenova\\Desktop\\chromedriver.exe"
driver=webdriver.Chrome(executable_path=path) #from where need to execute the path #
# driver=webdriver.Chrome()
driver.get("https:\\www.clubfactory.com\\")
driver.implicitly_wait(10) # It will wait till the browser and the url is loaded. Take the time is sec#
driver.maximize_window()
time.sleep(3) #import time package to check the browser is completely opened#
driver.quit()


0
09914040666 Replied on 02/04/2020

Hey, 

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 '__init__.py' 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


K
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?


0
09914040666 Replied on 19/05/2020

Hey, 

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