nose-devs/nose — Issue #71: Not possible to write plugin that includes doctests from "_*.py" files
Author: jpellerin
Created: 2011-12-14 15:57:54+00:00
State: closed

What steps will reproduce the problem?

Run functional test in attached patch (I will attempt to attach it after
I've created the issue, since the patch will reference the issue ID...).

The test attempts to run a plugin that runs doctests in files whose names
match the pattern "_*.py". The test also verifies that the behaviour of
nose without the plugin enabled is unchanged.

What is the expected output? What do you see instead?

Expected: above test passes.
Got: above test fails.

What version of the product are you using? On what operating system?

http://python-nose.googlecode.com/svn/branches/0.10.0-stable revision 309
on Ubuntu Linux

Please provide any additional information below.

Why I want this
---------------

I use a package structure like this:

$ ls mypackage
__init__.py
_implementation_module_a.py
_implementation_module_b.py
$ cat mypackage/__init__.py
__all__ = ["Foo", "Bar", "Spam"]
from _implementation_module_a import Foo, Bar
from _implementation_module_a import Spam

Then, users of mypackage are expected to import names only directly from
mypackage. _implementation_module_a.py and _implementation_module_b.py
may contain doctests, which should be run. Currently, it is not possible
to achieve that by writing a nose plugin, because nose.loader hard-codes
the check for initial underscore. Note that the same problem applies to
sub-packages whose directory names begin with '_'.

Patch
-----

The attached patch is minimal. It makes it possible to write a plugin to
run these doctests, but does not change the default behaviour of nose. I
imagine you will want to go further. This is what I would do (ask if you
want me to write a patch):

1. Make the analogous change for initial '.', so that plugins can also
override that behaviour.

2. Remove hard-coded checks in nose.selector.Selector.wantFile() for
initial '.' and '_', since those cases are already covered by the default
value of nose.config.Config.ignoreFiles. I was being a bit anal here,
aiming not to break code even if that code changes .ignoreFiles, since
nose is in beta. Probably that's going too far.

3. Make the default behaviour of nose be to run doctests even in modules
and packages whose names start with '_'. This would have to wait for nose
1.0, presumably.

The obvious problem with suggestion 3. above is that this would have the
side-effect of causing nose to load non-doctest tests from
initial-underscore modules. Idea for nose 1.0: perhaps new
methods .pluginWant*() could be added, to affect only the
dirs/files/modules/classes/functions seen by that plugin. Haven't worked
that idea through, though, so maybe it's no good.

Google Code Info:
Issue #: 82
Author: j...@pobox.com
Created On: 2007-08-25T15:44:54.000Z
Closed On: 2008-04-03T23:35:25.000Z