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

Show original pytest nodeid in report #833

Open
1 of 3 tasks
dengmingcong opened this issue Nov 20, 2024 · 0 comments
Open
1 of 3 tasks

Show original pytest nodeid in report #833

dengmingcong opened this issue Nov 20, 2024 · 0 comments

Comments

@dengmingcong
Copy link

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?

Cannot get the original pytest nodeid in Allure report.

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

What is the expected behavior?

The original pytest nodeid can be found in Allure report.

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

For pytest parameterized test cases using the ids parameter:

import allure
import pytest


@allure.title("Test with parameter id")
@pytest.mark.parametrize("item", ["foo", "bar"], ids=["f", "b"])
def test_parameter_id(item):
    pass

I am unable to programmatically establish a correspondence between pytest test cases and test cases in the Allure report because the parameter part of the pytest nodeid uses the values from the ids parameter, and Allure cannot obtain this parameter id, only the parameter values. Therefore, it is not possible to determine the correspondence by comparison. I would like to display the original pytest nodeid in the Allure report to facilitate comparison.

Additionally, although the list is ordered, my program treats each parameter as a separate test case, which may disrupt the parameter values, making it impossible to establish a correspondence based on the list index.

File details:

pytest test case collection result (using the command pytest --collect-only --collect-report=out.json tests/test_parameter_id.py):

{
  "pytest_version": "7.4.4",
  "plugin_version": "0.4.0",
  "exit_status": 0,
  "errors": [],
  "warnings": [],
  "items": [
    {
      "node_id": "tests/test_parameter_id.py::test_parameter_id[f]",
      "name": "test_parameter_id[f]",
      "doc": "",
      "markers": [
        "parametrize"
      ],
      "parameters": {
        "item": "str"
      },
      "file": "tests/test_parameter_id.py",
      "module": "tests.test_parameter_id",
      "parent": null,
      "function": "test_parameter_id"
    },
    {
      "node_id": "tests/test_parameter_id.py::test_parameter_id[b]",
      "name": "test_parameter_id[b]",
      "doc": "",
      "markers": [
        "parametrize"
      ],
      "parameters": {
        "item": "str"
      },
      "file": "tests/test_parameter_id.py",
      "module": "tests.test_parameter_id",
      "parent": null,
      "function": "test_parameter_id"
    }
  ]
}

Allure report data (one of the files in the allure-report/data/test-cases directory):

{
  "uid" : "4b6e7144c3a976bd",
  "name" : "Test with parameter id",
  "fullName" : "tests.test_parameter_id#test_parameter_id",
  "historyId" : "e2125482cc28434b8f7c28be0620beb5",
  "time" : {
    "start" : 1732068540681,
    "stop" : 1732068540682,
    "duration" : 1
  },
  "status" : "passed",
  "flaky" : false,
  "newFailed" : false,
  "newBroken" : false,
  "newPassed" : false,
  "retriesCount" : 0,
  "retriesStatusChange" : false,
  "beforeStages" : [ {
    "name" : "continue_on_failure",
    "time" : {
      "start" : 1732068540681,
      "stop" : 1732068540681,
      "duration" : 0
    },
    "status" : "passed",
    "steps" : [ ],
    "attachments" : [ ],
    "parameters" : [ ],
    "stepsCount" : 0,
    "attachmentsCount" : 0,
    "shouldDisplayMessage" : false,
    "hasContent" : false
  }, {
    "name" : "clean_session_variables",
    "time" : {
      "start" : 1732068540681,
      "stop" : 1732068540681,
      "duration" : 0
    },
    "status" : "passed",
    "steps" : [ ],
    "attachments" : [ ],
    "parameters" : [ ],
    "stepsCount" : 0,
    "attachmentsCount" : 0,
    "shouldDisplayMessage" : false,
    "hasContent" : false
  }, {
    "name" : "is_httprunner_test",
    "time" : {
      "start" : 1732068540681,
      "stop" : 1732068540681,
      "duration" : 0
    },
    "status" : "passed",
    "steps" : [ ],
    "attachments" : [ ],
    "parameters" : [ ],
    "stepsCount" : 0,
    "attachmentsCount" : 0,
    "shouldDisplayMessage" : false,
    "hasContent" : false
  } ],
  "afterStages" : [ ],
  "labels" : [ {
    "name" : "parentSuite",
    "value" : "tests"
  }, {
    "name" : "suite",
    "value" : "test_parameter_id"
  }, {
    "name" : "host",
    "value" : "Mac-mini.local"
  }, {
    "name" : "thread",
    "value" : "96997-MainThread"
  }, {
    "name" : "framework",
    "value" : "pytest"
  }, {
    "name" : "language",
    "value" : "cpython3"
  }, {
    "name" : "package",
    "value" : "tests.test_parameter_id"
  }, {
    "name" : "resultFormat",
    "value" : "allure2"
  } ],
  "parameters" : [ {
    "name" : "item",
    "value" : "'foo'"
  } ],
  "links" : [ ],
  "hidden" : false,
  "retry" : false,
  "extra" : {
    "severity" : "normal",
    "retries" : [ ],
    "categories" : [ ],
    "history" : {
      "statistic" : {
        "failed" : 0,
        "broken" : 0,
        "skipped" : 0,
        "passed" : 4,
        "unknown" : 0,
        "total" : 4
      },
      "items" : [ {
        "uid" : "a3a261bb1143179b",
        "reportUrl" : "../16096/index.html#testresult/a3a261bb1143179b",
        "status" : "passed",
        "time" : {
          "start" : 1731989755097,
          "stop" : 1731989755097,
          "duration" : 0
        }
      }, {
        "uid" : "2ae7fba6211f609",
        "reportUrl" : "../16095/index.html#testresult/2ae7fba6211f609",
        "status" : "passed",
        "time" : {
          "start" : 1731989755097,
          "stop" : 1731989755097,
          "duration" : 0
        }
      }, {
        "uid" : "df7585cb86f487dc",
        "reportUrl" : "../16094/index.html#testresult/df7585cb86f487dc",
        "status" : "passed",
        "time" : {
          "start" : 1731989755097,
          "stop" : 1731989755097,
          "duration" : 0
        }
      } ]
    },
    "tags" : [ ]
  },
  "source" : "4b6e7144c3a976bd.json",
  "parameterValues" : [ "'foo'" ]
}

Please tell us about your environment:

Other information

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant