nose-devs/nose2 — Issue #24: module fixtures don't run before test functions
Author: jpellerin
Created: 2012-01-26 22:05:50+00:00
State: open
Labels: 0.2, bug, release 0.1

Due to the way that unittest2's test suite detects and runs module fixtures, they don't run before test functions. If a test module contains only test functions, module fixtures don't run at all. If it contains a mixture of test functions and unittest.TestCases, the fixtures will be run around the test case tests only. This is because unittest2 detects module fixtures by looking at the __module__ set on the __class__ of the test case instance.

To work around this, nose2 will have to make a subclass of unittest2.FunctionTestCase for each test module containing functions, inject it into the module (and set __module__ on the class), and return instances of that class instead of the base.

Same for generators and parameters when they load from functions -- they must return instances of test classes that appear to be inside of the modules they are loading from.