1. 程式人生 > >python執行出現 ModuleNotFoundError: No module named 'xxx'問題

python執行出現 ModuleNotFoundError: No module named 'xxx'問題

執行程式碼時出現如下錯誤:

thread_資源競爭.py E
test setup failed
file D:\python\Spider\spider複習\Python多執行緒\thread_資源競爭.py, line 10
  def test1(num):
E       fixture 'num' not found
>       available fixtures: cache, capfd, capfdbinary, caplog, capsys, capsysbinary, doctest_namespace, monkeypatch, pytestconfig, record_property, record_xml_attribute, record_xml_property, recwarn, tmpdir, tmpdir_factory
>       use 'pytest --fixtures [testpath]' for help on them.

D:\python\Spider\spider複習\Python多執行緒\thread_資源競爭.py:10
E
test setup failed
file D:\python\Spider\spider複習\Python多執行緒\thread_資源競爭.py, line 21
  def test2(num):
E       fixture 'num' not found
>       available fixtures: cache, capfd, capfdbinary, caplog, capsys, capsysbinary, doctest_namespace, monkeypatch, pytestconfig, record_property, record_xml_attribute, record_xml_property, recwarn, tmpdir, tmpdir_factory
>       use 'pytest --fixtures [testpath]' for help on them.

D:\python\Spider\spider複習\Python多執行緒\thread_資源競爭.py:21
                                                    [100%]

=================================== ERRORS ====================================
___________________________ ERROR at setup of test1 ___________________________
file D:\python\Spider\spider複習\Python多執行緒\thread_資源競爭.py, line 10
  def test1(num):
E       fixture 'num' not found
>       available fixtures: cache, capfd, capfdbinary, caplog, capsys, capsysbinary, doctest_namespace, monkeypatch, pytestconfig, record_property, record_xml_attribute, record_xml_property, recwarn, tmpdir, tmpdir_factory
>       use 'pytest --fixtures [testpath]' for help on them.

D:\python\Spider\spider複習\Python多執行緒\thread_資源競爭.py:10
___________________________ ERROR at setup of test2 ___________________________
file D:\python\Spider\spider複習\Python多執行緒\thread_資源競爭.py, line 21
  def test2(num):
E       fixture 'num' not found
>       available fixtures: cache, capfd, capfdbinary, caplog, capsys, capsysbinary, doctest_namespace, monkeypatch, pytestconfig, record_property, record_xml_attribute, record_xml_property, recwarn, tmpdir, tmpdir_factory
>       use 'pytest --fixtures [testpath]' for help on them.

D:\python\Spider\spider複習\Python多執行緒\thread_資源競爭.py:21
=========================== 2 error in 0.13 seconds ===========================
Process finished with exit code 0

這是因為程式是在是在測試環境下執行的, 只要將環境改成 Unittests 就好了
具體操作

File--> Settings --> Tools --> Python Integrated Tools --> Default test runner , 將py.test改為Unittests即可;