【问题标题】:Eric IDE: running unit tests inside IDEEric IDE:在 IDE 中运行单元测试
【发布时间】:2018-05-13 14:28:26
【问题描述】:

我有一个小项目并正在运行单元测试:

$ python tests/runner.py 
......
----------------------------------------------------------------------
Ran 6 tests in 0.002s
OK
$ python -m tests.runner
......
----------------------------------------------------------------------
Ran 6 tests in 0.002s
OK

tests/runner.py:

import unittest

loader = unittest.TestLoader()
tests = loader.discover('.')
testRunner = unittest.runner.TextTestRunner()
testRunner.run(tests)

tests/test_common.py(单个测试用例,仅此而已):

from procr.core.pcp import *  # pcp - module under test.

class TestHelpers(unittest.TestCase):

    def setUp(self):
        pass

    def tearDown(self):
        pass

    def test_something(self):
    ...

目录结构:

project/
  __init__.py
  procr/
    core/
      __init__.py
      pcp.py
    __init__.py
  tests/
    __init__.py
    test_common.py
    runner.py

Eric IDE 需要一个测试或测试套件文件。提供runner.py,它报告Error: suite(unittest.loader._FailedTest)。项目目录设置为project,完整路径。

可能有什么问题?

更新:

测试甚至实际运行,如 Eric 控制台中所示。 IDE 可能期望与运行程序有些不同。我不知道是什么。

【问题讨论】:

  • tests = loader.discover('.'),这个点当前目录是否导致问题?你没有提到eric的位置。
  • Eric 项目目录正确:与成功运行 shell 示例的目录相同。

标签: python-unittest eric-ide


【解决方案1】:

这不是 Eric 单元测试手册,无论如何都不是。然而,总比没有好。至少向前迈出了一小步。

tests/test_common.py 的软链接(否则工作目录会从project 转移):

project/
  __init__.py
  procr/
    core/
      __init__.py
      pcp.py
    __init__.py
  tests/
    __init__.py
    test_common.py
    runner.py

  eric_test_common.py -> tests/test_common.py

Eric 单元测试对话框:

  • Enter test filenameeric_test_common.py 的完整路径

  • Enter test name:TestHelpers

  • Run local:检查

  • Start:推

这只是我发现的第一个可行选项;肯定还有更多。希望能及时完善这个答案。

Eric Unittest Dialog on GitHub

【讨论】:

    猜你喜欢
    • 2014-02-20
    • 2017-04-28
    • 1970-01-01
    • 2016-07-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多