Fix regression: allure_pytest.utils.allure_title crashes if obj attr doesn't exist (Fixes #733) #734
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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