Skip to content

The "excluded" and "mode" parameters of the allure.dynamic.parameter function are ignored for the pytest parameters #822

Open

Description

@RealMaxos

I'm submitting a ...

  • bug report
  • feature request
  • support request => Please do not submit support request here, see note at the top of this template.

What is the current behavior?

The "excluded" and "mode" parameters of the allure.dynamic.parameter function do not affect the display of the pytest parameter in the TestOps report.

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem

My test looks something like this:

@pytest.mark.parametrize('login, password', [('admin', 'secret')])
def test_authorization(login, password):
    allure.dynamic.parameter('password', password, mode=allure.parameter_mode.MASKED)
    ...

In this case, the parameters of the test function are passed using pytest.mark.parametrize.

The output of the report file looks like this:

{"name": "test_authorization[admin-secret]", "status": "passed", "parameters": [{"name": "login", "value": "'admin'"}, {"name": "password", "value": "'secret'"}], "start": 1718844940592, "stop": 1718844940592, "uuid": "1f59becc-6d3a-4be3-be5b-0ffbd257ec5b", "historyId": "36ae0f9494e1ff5a9b8153a55ab15428", "testCaseId": "2334cf5fc2f37123d71eab12c56f1a15", "fullName": "test_main#test_authorization", "labels": [{"name": "suite", "value": "test_main"}, {"name": "host", "value": "MYHOST"}, {"name": "thread", "value": "12440-MainThread"}, {"name": "framework", "value": "pytest"}, {"name": "language", "value": "cpython3"}, {"name": "package", "value": "test_main"}]}

What is the expected behavior?

The value of the "password" parameter is expected to be masked in the report.

What is the motivation / use case for changing the behavior?


Please tell us about your environment:

  • Allure version: 2.10.0
  • Test framework: pytest@8.2.2
  • Allure adaptor: allure-pytest@2.13.5

Other information

The solution method:

Change the method of the AllureListener class to allure_pytest/listener.py

Current code:

@allure_commons.hookimpl
def add_parameter(self, name, value, excluded, mode: ParameterMode):
    test_result: TestResult = self.allure_logger.get_test(None)
    existing_param = next(filter(lambda x: x.name == name, test_result.parameters), None)
    if existing_param:
        existing_param.value = represent(value)
    else:
        test_result.parameters.append(
            Parameter(
                name=name,
                value=represent(value),
                excluded=excluded or None,
                mode=mode.value if mode else None
            )
        )

Proposal for a change:

@allure_commons.hookimpl
def add_parameter(self, name, value, excluded, mode: ParameterMode):
    test_result: TestResult = self.allure_logger.get_test(None)
    existing_param = next(filter(lambda x: x.name == name, test_result.parameters), None)
    if existing_param:
        existing_param.value = represent(value)
        existing_param.excluded = excluded or None
        existing_param.mode = mode.value if mode else None
    else:
        test_result.parameters.append(
            Parameter(
                name=name,
                value=represent(value),
                excluded=excluded or None,
                mode=mode.value if mode else None
            )
        )

With this implementation, the result file will look like this:

{"name": "test_authorization[admin-secret]", "status": "passed", "parameters": [{"name": "login", "value": "'admin'"}, {"name": "password", "value": "'secret'", "mode": "masked"}], "start": 1718845042635, "stop": 1718845042635, "uuid": "88fa5ba0-faf1-40b0-a380-32c51a5f8907", "historyId": "36ae0f9494e1ff5a9b8153a55ab15428", "testCaseId": "2334cf5fc2f37123d71eab12c56f1a15", "fullName": "test_main#test_authorization", "labels": [{"name": "suite", "value": "test_main"}, {"name": "host", "value": "MYHOST"}, {"name": "thread", "value": "4536-MainThread"}, {"name": "framework", "value": "pytest"}, {"name": "language", "value": "cpython3"}, {"name": "package", "value": "test_main"}]}

Activity

  1. added
    task:improvementChange that improves some user experience but can't be considered a new feature
    on Jan 22, 2025
  2. kieran-ryan commented on Oct 11, 2026

    @kieran-ryan
    Contributor

    While #895 is pending, the below workaround can be integrated within your environment.

    from typing import Any
    
    from allure_commons import plugin_manager
    from allure_commons.model2 import Parameter, TestResult
    from allure_commons.types import ParameterMode
    from allure_commons.utils import represent
    
    def add_allure_parameter(
        name: str,
        value: Any,
        excluded: bool | None = None,
        mode: ParameterMode | None = None,
    ) -> None:
        listener = next(
            p
            for p in plugin_manager.get_plugins()
            if p.__class__.__name__ == "AllureListener"
        )
        test_result: TestResult = listener.allure_logger.get_test(None)
        existing_param = next((p for p in test_result.parameters if p.name == name), None)
    
        if existing_param:
            existing_param.value = represent(value)
            existing_param.excluded = excluded
            existing_param.mode = mode.value if mode else None
        else:
            test_result.parameters.append(
                Parameter(
                    name=name,
                    value=represent(value),
                    excluded=excluded,
                    mode=mode.value if mode else None,
                )
            )

    Sample call from a pytest test as follows.

    @pytest.mark.parametrize("param", [object()])
    def test_parameter_override(param):
        add_allure_parameter("param", param, excluded=True)

    This produces the following Allure JSON output.

    {
      "name": "test_parameter_override[param0]",
      "status": "passed",
      "parameters": [
        {
          "name": "param",
          "value": "<object object at 0x103475870>",
          "excluded": true
        }
      ],
      "start": 1791749801070,
      "stop": 1791749801070,
      "uuid": "d0d687d6-1161-4bfb-8f33-ee4aeab45584",
      "historyId": "10758b0f5b798dd0e48ea0545c1a35bd",
      "testCaseId": "10758b0f5b798dd0e48ea0545c1a35bd",
      "fullName": "runner.test_func#test_parameter_override",
      "labels": [
        { "name": "parentSuite", "value": "tests" },
        { "name": "suite", "value": "test_func" },
        { "name": "host", "value": "Mac" },
        { "name": "thread", "value": "38828-MainThread" },
        { "name": "framework", "value": "pytest" },
        { "name": "language", "value": "cpython3" },
        { "name": "package", "value": "tests.test_func" }
      ],
      "titlePath": ["tests", "test_func.py"]
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    task:improvementChange that improves some user experience but can't be considered a new featuretheme:pytest

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions