Accessing test file name from conftest.py
问题 What I'm trying to do I'm writing a small framework in python using pytest, and as part of the teardown I am taking a screenshot. Now, I want that screenshot to be named according to the running test, not conftest.py So, for example, my code right now is: driver.save_screenshot(os.path.basename(__file__)+'.png') The problem This prints the name "conftest.py". I want to print the calling test name if possible. I am guessing using requests? 回答1: You can access the current file path via request