我有一个由Travis在Linux和Windows上构建的软件包。用鼻子进行测试。
nosetests --with-coverage --cover-package=terminalplot
在Linux上,所有4个测试均已成功执行。
$ nosetests --with-coverage --cover-package=terminalplot
....
Name Stmts Miss Cover
--------------------------------------------------
terminalplot/__init__.py 1 0 100%
terminalplot/command.py 25 11 56%
terminalplot/terminalplot.py 27 3 89%
terminalplot/version.py 1 0 100%
--------------------------------------------------
TOTAL 54 14 74%
----------------------------------------------------------------------
Ran 4 tests in 0.013s
在Windows上,同样的代码运行也没有错误,但是报告说未执行任何测试。
$ nosetests --with-coverage --cover-package=terminalplot
The command "nosetests --with-coverage --cover-package=terminalplot" exited with 0.
Coveralls报告说某些部分已经覆盖,所以我认为已经运行了。
$ coveralls
Name Stmts Miss Cover
--------------------------------------------------
terminalplot\__init__.py 1 0 100%
terminalplot\terminalplot.py 27 23 15%
--------------------------------------------------
TOTAL 28 23 18%
----------------------------------------------------------------------
Ran 0 tests in 0.016s
测试位于单元测试类的测试包中。显然,这些测试是在Linux上轻易找到的,我不知道为什么在Windows上找不到这些测试。
项目结构
.
+- terminalplot
| +- test
| | +- __init__.py
| | +- test_terminalplot.py
| |
| +- __init__.py
| +- terminalplot.py
| +- ...
|
+- ...
测试看起来像下面的测试
import unittest
class TestCommand(unittest.TestCase):
def test_list_floats(self):
self.assertEqual(cli.list_floats("1 0.1 -0.3"), [1, 0.1, -0.3])
完整代码在Github上
由于我只能访问Linux,因此我只能在Travis上尝试Windows方面的东西。这是相当乏味的。所以我希望有人能指出我正确的方向。
在Windows上,将--exe
标志添加到鼻子测试命令:
nosetests --exe --with-coverage --cover-package=terminalplot