allure-framework / allure-pytest

Deprecated, please use https://github.com/allure-framework/allure-python instead
Other
171 stars 83 forks source link

Allows step-wrapped functions to be used outside of a running test #96

Closed pupssman closed 7 years ago

pupssman commented 8 years ago

I've recently encountered a problem with allure.step-wrapped function in pytest_generate_tests -- they fail with ugly trace like

==================================== ERRORS ====================================
 ERROR collecting .tox/py27/tmp/testdir/test_steps_in_parametrize1/test_steps_in_parametrize.py 
test_steps_in_parametrize.py:8: in pytest_generate_tests
    metafunc.parametrize('val', [foo()])
../../../local/lib/python2.7/site-packages/allure/common.py:56: in impl
    with StepContext(self.allure, self.title.format(*a, **kw)):
../../../local/lib/python2.7/site-packages/allure/common.py:34: in __enter__
    self.step = self.allure.start_step(self.title)
../../../local/lib/python2.7/site-packages/allure/pytest_plugin.py:159: in start_step
    self.stack[-1].steps.append(step)
E   AttributeError: 'AllureTestListener' object has no attribute 'stack'
=========================== 1 error in 0.27 seconds ============================

That is due to fact that stack is initialized per-test and only during pytest_runtest_protocol hook invocation. Added test manifest that behaviour.

The fix proposed is super-ugly, but does the trick. I'm considering other options -- but that may serve as an intermediate solution for now.

Proper fix not discard steps information from pre-test-run period but record them and display in the report.

pupssman commented 8 years ago

@mavlyutov plz C