سؤال

Basically in project I use following pattern:

package:
  __init__.py
  _mod1.py   
  _mod2.py

These modules are considered implementation detail and I don't want users to import them. I use doctests to test those internal modules. In default configuration nosetests won't find doctests in these modules.

I tried to fix it using match option (and doctest modules are matched), but I get dummy matches from python stdlib.

Details of system:

  • python 3.3
  • python is compiled from pythonz
  • I use virtualenv and virtualenvwrapper
  • nosetests are installed inside virtualenv
  • I use nose 1.3.0

Here is my nose config file:

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

Examples of bogus matches:

======================================================================
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'

----------------------------------------------------------------------
هل كانت مفيدة؟

المحلول

If you just want to prevent import, you could name your doctests with module.doctest (for instance), and use --doctest-extension=doctest. This approach is probably best practice.

If you are required to begin the module names with underscores, you'll need to replace nose's default ignore rule, which specifically excludes files named in the way that you named them. For instance, your doctests will be discovered if you add the following to your config:

ignore-files=DONTIGNOREANYFILES
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top