Adding test name to the pytest_runtest_call #9376
-
Hello everyone, I'm trying to add to the log the name of the test case that was being run when the test data is being generated. For experimentation purposes, I tried to add the following to the
The error message I'm getting is: which seems to suggest that I'm not supposed to be using it this way. My question is if there is a way for me to grab the test case name somehow before each test is run. The other way I could think of is going to each test file and trying to create a test fixture that would grab it that way, but thinking that if there are a lot of test files, that's going to be a bit of a pain to implement. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
However, the Long story short: |
Beta Was this translation helpful? Give feedback.
request
is a pytest fixture, i.e. exposed via a mechanism you can only access from tests or from other fixtures, but not from hooks (which, you could say, are more low-level in a sense).However, the
item
argument ofpytest_runtest_call
is the testItem
- andItem
is a subclass ofNode
, which is whatrequest.node
points at (Underlying collection node (depends on current request scope).).Long story short:
item.name
should get you there!