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即可;

猜你喜欢

转载自blog.csdn.net/qq_42827960/article/details/85246385