pytest icon indicating copy to clipboard operation
pytest copied to clipboard

FixtureRequest.node should be typed to return a Node

Open sk- opened this issue 1 month ago • 2 comments

Currently the property node of FixtureRequest is defined as

    @property
    @abc.abstractmethod
    def node(self):
         """Underlying collection node (depends on current request scope)."""
         raise NotImplementedError()

which implicitly types the return type as Any. However, based on the name of the function and the underlying implementations it should return a nodes.Node.

Unfortunately, when I tried this on a fork, I got the following error:

mypy............................................................................Failed
- hook id: mypy
- exit code: 1

src/_pytest/junitxml.py:294: error: "Node" has no attribute "user_properties"  [attr-defined]
Found 1 error in 1 file (checked 239 source files)

This happens because junitxml actually expects to receive a nodes.NodeItem instead of a plain nodes.Node.

One quick fix for this would be to put a type assertion in junitxml, but I'm not sure if that's the preferred approach. I'd be happy to send a PR if someone could give ve some guidance on how to best resolve this.

sk- avatar Nov 08 '25 14:11 sk-