Hacktoberfest 2026: die Issues, die Maintainer für den Oktober markiert haben – offen und einsteigerfreundlich. Hacktoberfest-Issues durchsuchen

Attribute error in @allure.title when using @pytest.fixture(params=[...]

Offen
#873 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Anfängerfreundlichkeit
45/100
Issue-Typ
Bug
Klarheit
Größtenteils klar
Aktivitätsstatus
Veraltet
Tech-Stack
python
Bereich
testing

Rechercherichtung

Beginne beim Formatierungspfad von @allure.title und bei allure_commons.utils.SafeFormatter.get_field, die im Traceback angezeigt werden; vergleiche dies mit dem in #670 beschriebenen Verhalten. Reproduziere die Skip- und Fehlerfälle von parametrisierten Fixtures und überprüfe anschließend, dass der ursprüngliche pytest-Skip oder ValueError statt eines AttributeError gemeldet wird.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

theme:pytest

@allure.title decorator doesn't correctly formats a title string when using a parametrized fixture and having that fixture skip a test or raise an error:

import pytest
import allure


class TestClass:
    @pytest.fixture(params=[1, 2])  # <-- causes AttributeError: 'int' object has no attribute 'one'
    # @pytest.fixture()
    def params(self):
        # will cause AttributeError in allure.title
        # if this fixture is skipping tests
        pytest.skip('skip')
        
        # or raising an error
        raise ValueError('aa')

        class _Params:
            """some params every test needs"""
            one = 1
            two = 2

        # but no error if it returns a value
        return _Params()

    @allure.title('should display "1" {params.one}')
    def test_func(self, params):  # <-- causes AttributeError: 'int' object has no attribute 'one'
        assert params.one == 1
self = <allure_commons.utils.SafeFormatter object at 0x7f1851ab19d0>, field_name = 'params.one', args = (), kwargs = {'param_id': '2', 'params': 2}

    def get_field(self, field_name, args, kwargs):
        first, rest = _string.formatter_field_name_split(field_name)
    
        obj = self.get_value(first, args, kwargs)
    
        # loop through the rest of the field_name, doing
        #  getattr or getitem as needed
        for is_attr, i in rest:
            if is_attr:
>               obj = getattr(obj, i)
                      ^^^^^^^^^^^^^^^
E               AttributeError: 'int' object has no attribute 'one'

/usr/lib64/python3.12/string.py:305: AttributeError
=================================================================== short test summary info ====================================================================
ERROR p.py::TestClass::test_func[1] - AttributeError: 'int' object has no attribute 'one'
ERROR p.py::TestClass::test_func[2] - AttributeError: 'int' object has no attribute 'one'
====================================================================== 2 errors in 0.14s =======================================================================

This is shadowing the real error or skip in the fixture and is similar to #670

allure-pytest==2.15.0
pytest==8.4.1
Vorherrschende Sprache
Python
Sterne
819
Forks
261
Ø Merge
3 Std. 20 Min.
Gemergte PRs (30 T.)
3

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus allure-framework/allure-python

Alle Issues in allure-framework/allure-python

Ähnliche Issues

Weitere Issues zu Python

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.