Run pytest, error "AttributeError: 'module' object has no attribute 'xxx'"

 Learn pytest recently been plagued by this problem, knock skull, really should not. Baidu solution a lot, my question is how can not be resolved, look, how I solved, you do not spray big brother, but with their own notes, thank you.

Given the information as follows:

 

Online solution is this:

1. Name py script, not with python reserved words, and so the same module name

2. Delete the library .pyc file (as will generate .pyc py script file for each run; in the case of .pyc file has been generated, if the code is not updated, the runtime will still go pyc, so you want to delete. .pyc searching for a file or code execution environment, the machine can replace the current copy; the pyc files), the code re-run

 PS: This method can not solve my problem.

 

Own solution:

Uninstall and reinstall pytest library

1, open cmd, enter the command: pip uninstall pytest

2, if prompted to remove failed to find D: \ python \ Lib \ site-packages of pytest] [file (the path where the installation path based on individual varies), delete the file, and then repeat the first step to again .

3, in order to see if the uninstall is complete, enter pip list view all installed modules, if you uninstall module operation is successful, you will no longer see [module] pytest

4, and then use pip install pytest command to reinstall

After running pytest, shows the version number, the installation is successful

 

Guess you like

Origin www.cnblogs.com/happywu205/p/11567882.html