-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
report.nodeid is not proper in pytest_runtest_logreport() hook for setup/teardown #4629
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
please show the actual code - and use the github code formatting so we can actually read it |
oh, also all setup of higher scopes currently happens at the setup stage of one item, which is the reported item |
My test is really simple: =============pytest_task.py=============== import pytest
def setup_module(module):
#raise Exception('wrong')
pass
def teardown_module(module):
#raise Exception('wrong')
pass
class TestClassOne(object):
@classmethod
def setup_class(cls):
#raise Exception('wrong')
pass
@classmethod
def teardown_class(cls):
#raise Exception('wrong')
pass
def setup_method(self, method):
#raise Exception('wrong')
pass
def teardown_method(self, method):
#raise Exception('wrong')
pass
def test_success(self):
assert 1 == 1
def test_failure(self):
assert True is False ================py_test.py============= import pytest
class PyTestPlugin(object):
def pytest_runtest_logreport(self, report):
# Here I want to log something
_pytest_plugin = PyTestPlugin()
return_code = pytest.main(['pytest_task.py'], plugins=[_pytest_plugin]) ===========================
also, I can only print the setup/teardown if they failed. But first of all, I need to know if the result of setup/teardown in each scope. Now, in pytest_runtest_logreport() hook, while report.when is setup or teardown, it only means something went wrong, but I don't know where it is. |
currently all setup of outer scopes happens at the time of the first setup, so indeed there is no direct way to tell where it went wrong with fixtures, or the upcoming #4091 you can tell |
Closing as inactive. |
I ran pytest 3.6.0 with python 3.4 on redhat 6.
I have a module pytest_tasks.py and a test class named 'TestClassOne', in which there's a testcase named 'test_success'. And I wrote a plugin with pytest_runtest_logreport() hook.
If I define a setup_method(self, method) in TestClassOne, then in pytest_runtest_logreport(self, report) I can get:
report.when == 'setup'
report.nodeid == 'pytest_tasks.py::TestClassOne::()::test_success'
I think this information is correct.
If I define a classmethod setup_class(cls), or a setup_module(module) in module scope, then I would expect to have report.nodeid equal to 'pytest_tasks.py::TestClassOne' and 'pytest_tasks.py' respectively, because the setup() works in suite scope or module scope, but the value is always 'pytest_tasks.py::TestClassOne::()::test_success'. So when I get a setup report I don't know which level it is, how can I get the correct information ?
The text was updated successfully, but these errors were encountered: