Skip to content

Pytest: Display path different from real path #23351

@PicouAymeric

Description

@PicouAymeric

In my pytest plugin, I generate a lot of tests on the same test function / same class / same module. Using pytest hook pytest_generate_tests
In order to be able to to run just a subset of my tests I would like to create virtual subset of my tests eventhough they are in the end running the same test function.

The idea would be to create a pytest_pycollect_makeitem hook function in my plugin to set a display prop on all my test different from nodeid

    def pytest_pycollect_makeitem(self, collector, name, obj):
        report = yield
        items = report.get_result()
        new_results = []
        for item in items:
            item.display = [display path depending on the test]
            new_results.append(item)
        return new_results

Then in Vscode testing tab I would have the display prop displayed instead of nodeid, but if we run that test it still runs the nodeid test.
In a previous version of Vscode I found a hack by changing fspath and _nodeid of my test then force session.config.args to my actual test module in pytest_collection, but this broke after a vscode upate (I kind of expected it to break someday)

Do you think it would be possible to differentiate the test path displayed and the test path executed?

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions