question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:13 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
TimurNurlygayanovcommented, Apr 25, 2018

The workaround I’ve applied for this issue:

Fix in Lines 56-60: /usr/local/lib/python3.5/dist-packages/allure_commons/reporter.py

    def start_after_fixture(self, parent_uuid, uuid, fixture):
        try:
            self._items.get(parent_uuid).afters.append(fixture)
            self._items[uuid] = fixture
        except:
            self._items[uuid] = fixture
            print('this allure failed')

Now it works, but it is a dirty workaround, please fix the lib for this case.

Thank you!

0reactions
UANEMESIScommented, Dec 13, 2022

I wasn`t able to reproduce it. Does someone still face it? If not, I will close the issue in a couple of weeks.

A lot of time has passed:) I think, it’s not actual now.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Python error; 'NoneType' object has no attribute 'after'
I got error while coding in python. Need to print same random value again & again. ... It looks like you are never...
Read more >
[FIXED] AttributeError: 'NoneType' object has no attribute ' ...
Hence, AttributeError: 'NoneType' object has no attribute 'something' error occurs when the type of object you are referencing is None.
Read more >
Python error; 'NoneType' object has no attribute 'after'
I got error while coding in python. Need to print same random value again & again. Code: [Select]. from Tkinter import * import...
Read more >
AttributeError: 'NoneType' object has no attribute ' ...
I am receiving the following error message after I register my app with reuters through the python API: AttributeError: 'NoneType' object has no...
Read more >
AttributeError: 'NoneType' object has no attribute 'group'
The Python "AttributeError: 'NoneType' object has no attribute" occurs when we try to call the group() method on a None value, e.g. after...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found