Skip to content

nose module fixtures are handled incorrectly #9272

@bluetech

Description

@bluetech

The current nose plugin does this:

if not call_optional(func.obj, "setup"):
# Call module level setup if there is no object level one.
assert func.parent is not None
call_optional(func.parent.obj, "setup") # type: ignore[attr-defined]
def teardown_nose() -> None:
if not call_optional(func.obj, "teardown"):
assert func.parent is not None
call_optional(func.parent.obj, "teardown") # type: ignore[attr-defined]
# XXX This implies we only call teardown when setup worked.
func.addfinalizer(teardown_nose)

If the module defines setup, the plugin calls it for every test function (like pytest's setup_function). But nose calls it once for the module (like pytest's setup_module).

Furthermore, it seems to assume func.parent will be a Module, but when inside a test class it will be an Instance, i.e. it will call the class's setup (and won't look at the module).

Finally, the "if there is no object level one" is incorrect -- the module-level setup should be called regardless of whether there is an object-level one.

The func.parent is causing some problems for a refactor I'm trying to perform, so I'll look into fixing this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    plugin: noserelated to the nose integration builtin plugintype: bugproblem that needs to be addressed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions