GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Fix regression: allure_pytest.utils.allure_title crashes if obj attr doesn't exist (Fixes #733) by delatrie · Pull Request #734 · allure-framework/allure-python

Conversation

@delatrie

@delatrie delatrie commented Mar 5, 2023 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

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

  • Sign Allure CLA
  • Provide unit tests

Closes #733

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
delatrie added 3 commits March 6, 2023 03:35
@delatrie
Fix allure_title regression (#733)
e3b0a5a
@delatrie
Fix runner for tests that import allure_pytest; Doc runner attrs
2de38a7
@delatrie
Fix linting errors
4e0f310
@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
skhomuti
skhomuti approved these changes Mar 14, 2023
View reviewed changes
@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
@delatrie @GilBecker-Anaplan
Fix regression: allure_pytest.utils.allure_title crashes if obj attr …
e932cef
…doesn't exist (Fixes allure-framework#733) (allure-framework#734)
IvanBuruyane pushed a commit to IvanBuruyane/allure-python that referenced this pull request Mar 19, 2024
@delatrie
Fix regression: allure_pytest.utils.allure_title crashes if obj attr …
91b9482
…doesn't exist (Fixes allure-framework#733) (allure-framework#734)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

1 more reviewer
@skhomuti skhomuti skhomuti approved these changes
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@delatrie delatrie

Labels

bug Something isn't working theme:pytest

Projects

None yet

Milestone

No milestone

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

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@delatrie @skhomuti
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.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.