不同目錄存在相同名稱的py文件,執行時,報錯的解決方法


1、問題現象如下,執行時報錯  imported module 'test_case_execution' has this __file__ attribute

platform win32 -- Python 3.6.5, pytest-4.6.3, py-1.8.0, pluggy-0.12.0 -- E:\Program Files (x86)\Python36-32\python.exe
cachedir: .pytest_cache
rootdir: F:\pythonLear\PyTest_allure_apitest-master
plugins: allure-adaptor2-1.7.11, rerunfailures-7.0
collecting ... collected 4 items / 1 errors / 3 selected

=================================== ERRORS ====================================
_ ERROR collecting TestCase/test_airticket/test_app_airticket_search/test_case_execution.py _
import file mismatch:
imported module 'test_case_execution' has this __file__ attribute:
  F:\pythonLear\PyTest_allure_apitest-master\TestCase\test_airticket\test_app_airticket_login\test_case_execution.py
which is not the same as the test file we want to collect:
  F:\pythonLear\PyTest_allure_apitest-master\TestCase\test_airticket\test_app_airticket_search\test_case_execution.py
HINT: remove __pycache__ / .pyc files and/or use a unique basename for your test file modules
!!!!!!!!!!!!!!!!!!! Interrupted: 1 errors during collection !!!!!!!!!!!!!!!!!!!
=========================== 1 error in 0.39 seconds ===========================

Process finished with exit code 0

2、解決方法

在同名文件所在目錄下添加__init__.py文件即可解決問題


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM