Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

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

Abierto
#873 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
3/5
Tiempo estimado
1-2 días
Aptitud para principiantes
45/100
Tipo de issue
Error
Claridad
Bastante claro
Estado de actividad
Estancado
Stack tecnológico
python
Área
testing

Línea de trabajo

Comienza en la ruta de formateo de @allure.title y en allure_commons.utils.SafeFormatter.get_field que se muestran en el traceback; compárala con el comportamiento descrito en #670. Reproduce los casos de omisión y error de un fixture parametrizado y verifica después que se informe del skip original de pytest o de ValueError en lugar de AttributeError.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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
Lenguaje dominante
Python
Estrellas
819
Forks
261
Merge medio
3 h 20 min
PR fusionados (30 d)
3

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de allure-framework/allure-python

Todos los issues de allure-framework/allure-python

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.