This pull request fixes the regression defect that could be observed if allure-pytest is run against a pytest item with no obj attribute or property. This is typical for items that have no meaningful object they can refer. The real-world examples are pytest-mypy's MypyItem and YamlItem from Working with non-python tests.
The breaking change was introduced during the work on #732. The intent was to get rid of exception-based flow control. The fix is just to add another getattr call instead of accessing the obj attribute directly.
AllureFileLogger patching fix
tests.e2e.allure_in_memory_context now always patches allure_commons.logger.AllureFileLogger in addition to provided paths.
Motivation
Generally, when setting up the in-memory logger, we want to patch the class imported by an integration-specific module (e.g., the allure_pytest.plugin.AllureFileLogger class), not the original one (i.e., allure_commons.logger.AllureFileLogger). This preloads the module and replaces the logger class with the in-memory logger. The module is then removed from sys.modules by pytester once the test is completed and the next test repeats the sequence.
This works universally, regardless of whether allure is enabled for the running session or not or whether we test allure-pytest, allure-behave or other integrations. The only exception is when there is a reference to the patched module that prevents it from being unloaded. The patched module gets reimported by a pytester and the patching appears to have no effect.
Example
From ./tests/allure_pytest/defects/issue733_test.py:
from allure_pytest.utils import allure_title
# ...
The ref chain after the first end-to-end test on allure-pytest is executed:
Consequently, all in-memory end-to-end tests will fail.
Now if we also patch allure_commons.logger.AllureFileLogger, the correct class is imported when pytester reimports the module and the tests pass.
Context
This pull request fixes the regression defect that could be observed if allure-pytest is run against a pytest item with no
obj
attribute or property. This is typical for items that have no meaningful object they can refer. The real-world examples are pytest-mypy's MypyItem andYamlItem
from Working with non-python tests.The breaking change was introduced during the work on #732. The intent was to get rid of exception-based flow control. The fix is just to add another
getattr
call instead of accessing theobj
attribute directly.AllureFileLogger patching fix
tests.e2e.allure_in_memory_context
now always patchesallure_commons.logger.AllureFileLogger
in addition to provided paths.Motivation
Generally, when setting up the in-memory logger, we want to patch the class imported by an integration-specific module (e.g., the
allure_pytest.plugin.AllureFileLogger
class), not the original one (i.e.,allure_commons.logger.AllureFileLogger
). This preloads the module and replaces the logger class with the in-memory logger. The module is then removed fromsys.modules
by pytester once the test is completed and the next test repeats the sequence.This works universally, regardless of whether allure is enabled for the running session or not or whether we test
allure-pytest
,allure-behave
or other integrations. The only exception is when there is a reference to the patched module that prevents it from being unloaded. The patched module gets reimported by a pytester and the patching appears to have no effect.Example
From
./tests/allure_pytest/defects/issue733_test.py
:The ref chain after the first end-to-end test on allure-pytest is executed:
Consequently, all in-memory end-to-end tests will fail.
Now if we also patch
allure_commons.logger.AllureFileLogger
, the correct class is imported when pytester reimports the module and the tests pass.Checklist
Closes #733