nose-devs/nose — Issue #236: test-first directory sorting
Author: jpellerin
Created: 2011-12-14 16:04:51+00:00
State: open

For setup reasons, this is a request to change the sorting behavior (see
nose.loader.TestLoader.loadTestsFromDir) so that test-like entries are
loaded before non-test-like entries.

Thus, frameworks like django and pylons, which require app setup before
things can be imported, will have a chance to set up the app in
tests/__init__.py:setup(). For example, this pylons app:

project/app/controllers
project/app/model
project/app/lib/database
project/app/tests/__init__.py

...will fail when nosetests is run from the project dir with no args. This
is because app.lib.database is imported which will likely call something
like context.add_engine_from_config(...) yet the app was not "setup."

There are definitely edge cases where changing the order won't solve the
import problem (i.e. app/__init__.py could call setup-specific code, I
suppose).

The problem in general may be better addressed by this feature:
http://code.google.com/p/python-nose/issues/detail?id=116
(however, issue 116 without test-first sorting still opens up potential
problems, especially with doctests)

The original feature of test-last sorting was done so that "lib"
directories, or non-package folders could be added to the import path by
discovery. This will need to be re-implemented, possibly as a first-pass
iteration that descends from the root, looking for all directories leading
up to a package, then adding them to the path. For example:

project/lib/app/__init__.py
project/lib/app/controllers
...
project/tests/__init__.py

... a first-pass iteration would detect the app package and call:

importer.add_path('lib')

This change would probably also require more tests of the discovery process
to make sure other things don't break when entry sorting is reversed.

Some discussion:
http://groups.google.com/group/nose-dev/browse_thread/thread/83ccc0fbc32b0efc

Google Code Info:
Issue #: 118
Author: kumar.mcmillan
Created On: 2007-10-19T22:23:25.000Z
Closed On: