Skip to content

Conversation

@JiajunXu2
Copy link
Contributor

closes #12426
added conditional statement to check if usefixtures is empty, raises warning if there is no fixture names.

Copy link
Member

@RonnyPfannschmidt RonnyPfannschmidt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for getting this started

For better reporting of the mark application, the node.warn function should be used to ensure the function/class/module where the mark is used is reported

Additionally there's need for a test and a change log entry as per the contribution documentation

For easier iteration on this change I recommend using a branch different from main

"""Return the names of usefixtures fixtures applicable to node."""
for mark in node.iter_markers(name="usefixtures"):
if not mark.args:
warnings.warn(f"Warning: empty usefixtures in {node.name}.")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of using a direct warning, inter_marks_with_nodes ought to be used and node.warn should be used to ensure the warning reports the definition site for warning about the marks

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sorry, I don't understand what you mean by inter_marks_with_nodes. I was able to switch to node.warn, but I don't see inter_marks_with_nodes in the documentation. Could you please clarify?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh okay, understood. Thanks!

JiajunXu2 and others added 4 commits June 9, 2024 23:00
- Updated _getusefixturesnames to iterate with node and marker using node.iter_markers_with_node.
- Modified warning message to include the location of the marker node.
- Replaced warnings.warn with node.warn to issue warnings.
@psf-chronographer psf-chronographer bot added the bot:chronographer:provided (automation) changelog entry is part of PR label Jul 11, 2024
Copy link
Member

@RonnyPfannschmidt RonnyPfannschmidt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for starting this

def _getusefixturesnames(self, node: nodes.Item) -> Iterator[str]:
"""Return the names of usefixtures fixtures applicable to node."""
for mark in node.iter_markers(name="usefixtures"):
for marker_node, mark in node.iter_markers_with_node(name="usefixtures"):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need a automated test for this behavior and

for marker_node, mark in node.iter_markers_with_node(name="usefixtures"):
if not mark.args:
warnings.warn(f"Warning: empty usefixtures in {node.name}.")
location = getattr(marker_node, "location", "unknown location")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as per https://github.com/pytest-dev/pytest/blob/main/src/_pytest/nodes.py#L271 we tell the location of the node when warning, so why not just use marker_node.warn

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used marker_node.location, but sometimes I got an attribute error: node has no attribute 'location.' I can't seem to replicate the error. Would you prefer marker_node.warn?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that Will Auto fill the warning file and line

Copy link
Member

@nicoddemus nicoddemus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Besides @RonnyPfannschmidt comments, left small suggestions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot:chronographer:provided (automation) changelog entry is part of PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

pytest.mark.usefixtures() without argument gets silently ignored

3 participants