Skip to content

AttributeError: 'NoneType' object has no attribute 'afters' #216

Closed
@TimurNurlygayanov

Description

@TimurNurlygayanov

I'm submitting a ...

  • bug report
  • feature request

What is the current behavior?

When my test failed with Error, I've got the following traceback:

________ ERROR at teardown of test_check_search_deep[web_browser0-url0] ________

self = <allure_commons._allure.fixture object at 0x7f59926cb8d0>, args = ()
kwargs = {}, _args = {}, _kwargs = {}

    def __call__(self, *args, **kwargs):
        _args, _kwargs = func_parameters(self._fixture_function, *args, **kwargs)
        _args.update(kwargs)
        self.parameters = list(_args.items())
    
>       with self:

/usr/local/lib/python3.5/dist-packages/allure_commons/_allure.py:173: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
/usr/local/lib/python3.5/dist-packages/allure_commons/_allure.py:180: in __enter__
    parameters=self.parameters)
/usr/local/lib/python3.5/dist-packages/allure_pytest/listener.py:49: in start_fixture
    self.allure_logger.start_after_fixture(parent_uuid, uuid, after_fixture)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <allure_commons.reporter.AllureReporter object at 0x7f5992b14358>
parent_uuid = 'cae8132f-92c1-4911-86fa-5b3f3786ca79'
uuid = '64b974f7-eed7-4d71-ac75-94ffa7576ca4'
fixture = TestAfterResult(name='selenium::teardown', status=None, statusDetails=None, stage=None, description=None, descriptionHtml=None, steps=[], attachments=[], parameters=[], start=1524650380611, stop=None)

    def start_after_fixture(self, parent_uuid, uuid, fixture):
>       self._items.get(parent_uuid).afters.append(fixture)
E       AttributeError: 'NoneType' object has no attribute 'afters'

/usr/local/lib/python3.5/dist-packages/allure_commons/reporter.py:57: AttributeError

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem

I'm using PyTest and the following "good practices" hacks:

@pytest.hookimpl(hookwrapper=True, tryfirst=True)
def pytest_runtest_makereport(item, call):
    # Details: https://docs.pytest.org/en/latest/example/simple.html#making-test-result-information-available-in-fixtures
    # This function helps to detect that some test failed
    # and pass this information to teardown:

    outcome = yield
    rep = outcome.get_result()
    setattr(item, "rep_" + rep.when, rep)
@pytest.fixture(scope="function", params=[{'login': False}])
def web_browser(request, selenium):
    selenium.set_window_size(1400, 1000)

    # Return browser instance to test case:
    yield selenium

    # Do teardown (this code will be executed after each test):

    try:
        if 'rep_call' in dir(request.node):
            if request.node.rep_call.failed:
                # Make the screen-shot if test failed:
                selenium.execute_script("document.body.bgColor = 'white';")

                allure.attach(selenium.get_screenshot_as_png(),
                              name=request.function.__name__,
                              attachment_type=allure.attachment_type.PNG)

                # Make screen-shot for local debug:
                selenium.save_screenshot(str(uuid.uuid4()) + '.png')

                print("URL: ", selenium.current_url)
    except:
        pass # just ignore

What is the expected behavior?

No errors with traceback from allure.

What is the motivation / use case for changing the behavior?

Allure shouldn't be the reason of Error tests, and there is not clear workaround for the issue.

Please tell us about your environment:

allure-pytest==2.3.2b1
allure-python-commons==2.3.2b1
pytest-base-url==1.4.1
pytest-forked==0.2
pytest-html==1.16.1
pytest-metadata==1.6.0
pytest-selenium==1.12.0
pytest-variables==1.7.1
pytest-xdist==1.22.2

Other information

--

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions