py.test: how to get the current test's name from the setup method?

前端 未结 7 2155
心在旅途
心在旅途 2020-12-17 07:49

I am using py.test and wonder if/how it is possible to retrieve the name of the currently executed test within the setup method that is invoked before running e

7条回答
  •  攒了一身酷
    2020-12-17 08:38

    You can also use the PYTEST_CURRENT_TEST environment variable set by pytest for each test case.

    PYTEST_CURRENT_TEST environment variable

    To get just the test name:

    os.environ.get('PYTEST_CURRENT_TEST').split(':')[-1].split(' ')[0]
    

提交回复
热议问题