Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix regression: allure_pytest.utils.allure_title crashes if obj attr doesn't exist (Fixes #733) #734

Merged
merged 3 commits into from
Mar 14, 2023

Conversation

delatrie
Copy link
Contributor

@delatrie delatrie commented Mar 5, 2023

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 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.

Checklist

Closes #733

@delatrie delatrie added bug Something isn't working theme:pytest labels Mar 5, 2023
@delatrie delatrie requested a review from skhomuti March 5, 2023 22:43
@delatrie delatrie self-assigned this Mar 5, 2023
@delatrie delatrie marked this pull request as ready for review March 6, 2023 03:20
@delatrie delatrie merged commit 690c6ea into master Mar 14, 2023
@delatrie delatrie deleted the issue733-fix branch March 14, 2023 12:54
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working theme:pytest
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Regression in allure-pytest 2.13.0: crash in allure_title when called over pytest.Item with no .obj
2 participants