Skip to content

Is not possible import external module in conftest.py that use allure's decorators #75

@RockBomber

Description

@RockBomber

I'm submitting a bug report

Steps to reproduce and a minimal demo of the problem:
Create new PyTest project:
.
./mymodule
./mymodule/_init_.py
./conftest.py
./test_1.py

Content of ./mymodule/_init_.py:

import pytest

@pytest.allure.step('step one')
def step_one():
    pass

Content of ./conftest.py:

from mymodule import step_one

Content of ./test_1.py:

def test_0():
    pass

Then run it: pytest test_1.py --alluredir aresult

You will got an error:

$ pytest test_1.py --alluredir aresult
Traceback (most recent call last):
  File "/home/asdef/.virtualenvs/autotesting/local/lib/python2.7/site-packages/_pytest/config.py", line 373, in _importconftest
    mod = conftestpath.pyimport()
  File "/home/asdef/.virtualenvs/autotesting/local/lib/python2.7/site-packages/py/_path/local.py", line 662, in pyimport
    __import__(modname)
  File "/home/asdef/.virtualenvs/autotesting/local/lib/python2.7/site-packages/_pytest/assertion/rewrite.py", line 215, in load_module
    py.builtin.exec_(co, mod.__dict__)
  File "/home/asdef/.virtualenvs/autotesting/local/lib/python2.7/site-packages/py/_builtin.py", line 221, in exec_
    exec2(obj, globals, locals)
  File "<string>", line 7, in exec2
  File "/home/asdef/Dropbox/Work/Git/PyTestError/conftest.py", line 7, in <module>
    from mymodule import step_one
  File "/home/asdef/Dropbox/Work/Git/PyTestError/mymodule/__init__.py", line 6, in <module>
    @pytest.allure.step('step one')
AttributeError: 'module' object has no attribute 'allure'
ERROR: could not load /home/asdef/Dropbox/Work/Git/PyTestError/conftest.py

Workaround: import mymodule in test_1.py

Expected behavior: successful import of mymodule in conftest.py

Environment:

  • Python version: 2.7.8
  • Allure version: 2.2.1
  • Test framework: pytest@3.1.2
  • Allure adaptor: allure-pytest@2.0.0b2

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions