Fix regression: allure_pytest.utils.allure_title crashes if obj attr doesn't exist (Fixes #733)#734
Merged
Fix regression: allure_pytest.utils.allure_title crashes if obj attr doesn't exist (Fixes #733)#734
Conversation
skhomuti
approved these changes
Mar 14, 2023
beckerGil
pushed a commit
to beckerGil/allure-python
that referenced
this pull request
Apr 10, 2023
IvanBuruyane
pushed a commit
to IvanBuruyane/allure-python
that referenced
this pull request
Mar 19, 2024
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
objattribute or property. This is typical for items that have no meaningful object they can refer. The real-world examples are pytest-mypy's MypyItem andYamlItemfrom 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
getattrcall instead of accessing theobjattribute directly.AllureFileLogger patching fix
tests.e2e.allure_in_memory_contextnow always patchesallure_commons.logger.AllureFileLoggerin 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.AllureFileLoggerclass), 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.modulesby 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-behaveor 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