1

基本上在项目中我使用以下模式:

package:
  __init__.py
  _mod1.py   
  _mod2.py

这些模块被认为是实现细节,我不希望用户导入它们。我使用 doctests 来测试那些内部模块。在默认配置中,nosetests 不会在这些模块中找到 doctests。

我尝试使用match选项修复它(并且匹配 doctest 模块),但我从 python stdlib 获得了虚拟匹配。

系统详情:

  • 蟒蛇3.3
  • python是从pythonz编译的
  • 我使用 virtualenv 和 virtualenvwrapper
  • 鼻子测试安装在 virtualenv 中
  • 我用鼻子 1.3.0

这是我的鼻子配置文件:

[nosetests]
match=[^.][Tt]est
with-doctest=1
processes=50
process-timeout=25
verbosity=3
attr=!singleprocess
ignore-files=.*pythonz.*

虚假匹配的示例:

======================================================================
ERROR: Skip this test.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/jb/.pythonz/pythons/CPython-3.3.2/lib/python3.3/unittest/case.py", line 384, in _executeTestPart
    function()
TypeError: skipTest() missing 1 required positional argument: 'reason'

======================================================================
ERROR: Skip this test.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/jb/.pythonz/pythons/CPython-3.3.2/lib/python3.3/unittest/case.py", line 384, in _executeTestPart
    function()
TypeError: skipTest() missing 1 required positional argument: 'reason'

======================================================================
ERROR: Decorator to mark a function or method as a test
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/jb/.virtualenvs/silf-backend-commons/lib/python3.3/site-packages/nose/case.py", line 198, in runTest
    self.test(*self.arg)
  File "/home/jb/.virtualenvs/silf-backend-commons/lib/python3.3/site-packages/nose/util.py", line 613, in newfunc
    return func(*arg, **kw)
TypeError: istest() missing 1 required positional argument: 'func'

======================================================================
ERROR: Decorator to mark a function or method as *not* a test
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/jb/.virtualenvs/silf-backend-commons/lib/python3.3/site-packages/nose/case.py", line 198, in runTest
    self.test(*self.arg)
  File "/home/jb/.virtualenvs/silf-backend-commons/lib/python3.3/site-packages/nose/util.py", line 613, in newfunc
    return func(*arg, **kw)
TypeError: nottest() missing 1 required positional argument: 'func'

======================================================================
ERROR: Skip this test.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/jb/.pythonz/pythons/CPython-3.3.2/lib/python3.3/unittest/case.py", line 384, in _executeTestPart
    function()
TypeError: skipTest() missing 1 required positional argument: 'reason'

======================================================================
ERROR: Decorator to mark a function or method as a test
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/jb/.virtualenvs/silf-backend-commons/lib/python3.3/site-packages/nose/case.py", line 198, in runTest
    self.test(*self.arg)
  File "/home/jb/.virtualenvs/silf-backend-commons/lib/python3.3/site-packages/nose/util.py", line 613, in newfunc
    return func(*arg, **kw)
TypeError: istest() missing 1 required positional argument: 'func'

======================================================================
ERROR: Skip this test.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/jb/.pythonz/pythons/CPython-3.3.2/lib/python3.3/unittest/case.py", line 384, in _executeTestPart
    function()
TypeError: skipTest() missing 1 required positional argument: 'reason'

======================================================================
ERROR: Decorator to mark a function or method as a test
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/jb/.virtualenvs/silf-backend-commons/lib/python3.3/site-packages/nose/case.py", line 198, in runTest
    self.test(*self.arg)
  File "/home/jb/.virtualenvs/silf-backend-commons/lib/python3.3/site-packages/nose/util.py", line 613, in newfunc
    return func(*arg, **kw)
TypeError: istest() missing 1 required positional argument: 'func'

======================================================================
ERROR: Skip this test.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/jb/.pythonz/pythons/CPython-3.3.2/lib/python3.3/unittest/case.py", line 384, in _executeTestPart
    function()
TypeError: skipTest() missing 1 required positional argument: 'reason'

======================================================================
ERROR: Skip this test.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/jb/.pythonz/pythons/CPython-3.3.2/lib/python3.3/unittest/case.py", line 384, in _executeTestPart
    function()
TypeError: skipTest() missing 1 required positional argument: 'reason'

======================================================================
ERROR: Skip this test.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/jb/.pythonz/pythons/CPython-3.3.2/lib/python3.3/unittest/case.py", line 384, in _executeTestPart
    function()
TypeError: skipTest() missing 1 required positional argument: 'reason'

======================================================================
ERROR: Skip this test.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/jb/.pythonz/pythons/CPython-3.3.2/lib/python3.3/unittest/case.py", line 384, in _executeTestPart
    function()
TypeError: skipTest() missing 1 required positional argument: 'reason'

======================================================================
ERROR: Skip this test.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/jb/.pythonz/pythons/CPython-3.3.2/lib/python3.3/unittest/case.py", line 384, in _executeTestPart
    function()
TypeError: skipTest() missing 1 required positional argument: 'reason'

======================================================================
ERROR: Decorator to mark a function or method as a test
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/jb/.virtualenvs/silf-backend-commons/lib/python3.3/site-packages/nose/case.py", line 198, in runTest
    self.test(*self.arg)
  File "/home/jb/.virtualenvs/silf-backend-commons/lib/python3.3/site-packages/nose/util.py", line 613, in newfunc
    return func(*arg, **kw)
TypeError: istest() missing 1 required positional argument: 'func'

======================================================================
ERROR: Skip this test.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/jb/.pythonz/pythons/CPython-3.3.2/lib/python3.3/unittest/case.py", line 384, in _executeTestPart
    function()
TypeError: skipTest() missing 1 required positional argument: 'reason'

======================================================================
ERROR: Skip this test.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/jb/.pythonz/pythons/CPython-3.3.2/lib/python3.3/unittest/case.py", line 384, in _executeTestPart
    function()
TypeError: skipTest() missing 1 required positional argument: 'reason'

======================================================================
ERROR: Skip this test.
----------------------------------------------------------------------
nose.proxy.TypeError: skipTest() missing 1 required positional argument: 'reason'
-------------------- >> begin captured logging << --------------------
root: DEBUG: Firing event <EventObject power_up, (*('default',), **{})>
root: DEBUG: Firing event <EventObject tick, (*(), **{})>
--------------------- >> end captured logging << ---------------------

======================================================================
ERROR: Skip this test.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/jb/.pythonz/pythons/CPython-3.3.2/lib/python3.3/unittest/case.py", line 384, in _executeTestPart
    function()
TypeError: skipTest() missing 1 required positional argument: 'reason'

======================================================================
ERROR: Skip this test.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/jb/.pythonz/pythons/CPython-3.3.2/lib/python3.3/unittest/case.py", line 384, in _executeTestPart
    function()
TypeError: skipTest() missing 1 required positional argument: 'reason'

======================================================================
ERROR: Skip this test.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/jb/.pythonz/pythons/CPython-3.3.2/lib/python3.3/unittest/case.py", line 384, in _executeTestPart
    function()
TypeError: skipTest() missing 1 required positional argument: 'reason'

======================================================================
ERROR: Skip this test.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/jb/.pythonz/pythons/CPython-3.3.2/lib/python3.3/unittest/case.py", line 384, in _executeTestPart
    function()
TypeError: skipTest() missing 1 required positional argument: 'reason'

======================================================================
ERROR: Skip this test.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/jb/.pythonz/pythons/CPython-3.3.2/lib/python3.3/unittest/case.py", line 384, in _executeTestPart
    function()
TypeError: skipTest() missing 1 required positional argument: 'reason'

======================================================================
ERROR: Skip this test.
----------------------------------------------------------------------
nose.proxy.TypeError: skipTest() missing 1 required positional argument: 'reason'
-------------------- >> begin captured logging << --------------------
Test: INFO: Initializing experiment
Test: INFO: Initialized client
Test: INFO: Initialized manager
Test: INFO: Started main thread
--------------------- >> end captured logging << ---------------------

======================================================================
ERROR: Skip this test.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/jb/.pythonz/pythons/CPython-3.3.2/lib/python3.3/unittest/case.py", line 384, in _executeTestPart
    function()
TypeError: skipTest() missing 1 required positional argument: 'reason'

======================================================================
ERROR: Skip this test.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/jb/.pythonz/pythons/CPython-3.3.2/lib/python3.3/unittest/case.py", line 384, in _executeTestPart
    function()
TypeError: skipTest() missing 1 required positional argument: 'reason'

======================================================================
ERROR: Skip this test.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/jb/.pythonz/pythons/CPython-3.3.2/lib/python3.3/unittest/case.py", line 384, in _executeTestPart
    function()
TypeError: skipTest() missing 1 required positional argument: 'reason'

======================================================================
ERROR: Skip this test.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/jb/.pythonz/pythons/CPython-3.3.2/lib/python3.3/unittest/case.py", line 384, in _executeTestPart
    function()
TypeError: skipTest() missing 1 required positional argument: 'reason'

----------------------------------------------------------------------
4

1 回答 1

1

如果您只是想阻止导入,您可以使用 module.doctest(例如)命名您的 doctest,并使用 --doctest-extension=doctest。这种方法可能是最佳实践。

如果您需要以下划线开头的模块名称,则需要替换nose 的默认忽略规则,该规则专门排除以您命名它们的方式命名的文件。例如,如果您将以下内容添加到配置中,则会发现您的文档测试:

ignore-files=DONTIGNOREANYFILES
于 2013-08-13T21:35:31.693 回答