Eclipse运行Py.test报错:AttributeError: module 'pytest' has no attribute 'main'
Eclipse/PyDev中运行pytest报错:AttributeError: module 'pytest' has no attribute 'main'
我写了一段简单的Python测试代码:
def inc(x): return x + 1 def test_inc_pass(): assert inc(5) == 6 def test_inc_fail(): assert inc(5) == 5
当我尝试在Eclipse中通过py.test运行器直接执行这些测试时,出现了以下报错:
Traceback (most recent call last): File "C:\MojeApps\eclipse\plugins\org.python.pydev.core_7.6.0.202006041357\pysrc\runfiles.py", line 273, in <module> main() File "C:\MojeApps\eclipse\plugins\org.python.pydev.core_7.6.0.202006041357\pysrc\runfiles.py", line 265, in main return pytest.main(argv) AttributeError: module 'pytest' has no attribute 'main'
我已经尝试过通过pip uninstall pytest和pip install pytest重新安装pytest,但问题依然没有解决。有意思的是,在CMD命令行中运行测试一切正常,执行结果如下:
C:\Development\eclipse_workspace\PySandbox\pytest>pytest ========================================================================= test session starts ========================================================================== platform win32 -- Python 3.6.5, pytest-6.0.0, py-1.9.0, pluggy-0.13.1 rootdir: C:\Development\eclipse_workspace\PySandbox\pytest plugins: pydev-0.1.1 collected 2 items test_sample.py .F [100%] =============================================================================== FAILURES =============================================================================== ____________________________________________________________________________ test_inc_fail _____________________________________________________________________________ def test_inc_fail(): > assert inc(5) == 5 E assert 6 == 5 E + where 6 = inc(5) test_sample.py:9: AssertionError ======================================================================= short test summary info ======================================================================== FAILED test_sample.py::test_inc_fail - assert 6 == 5 ==================================================================== 1 failed, 1 passed in 0.14s ======================================================================
我猜测问题出在Eclipse/PyDev的配置上,有没有大佬能给我一些解决建议或者帮助?
内容的提问来源于stack exchange,提问作者otemek
相关产品推荐
相关产品推荐

