I am looking forward to list all the (pytest) test cases in the form of CSV.
Use case scenario: We already have test cases defined for multiple platforms and databases. These test cases are organized/grouped based on different markers (Ex : platform_linux, platform_centos, db_maria, db_mongo, db_redis etc).
I want to create a CSV file, that contains all the markers and test cases that belong the marker.
Sample of CSV file:
> Marker, Test Cases
> platform_linux, [test_linux1, test_linux2...]
> db_mariadb, [test_mariadb1, test_mariadb2...]
Goal here is to process the CSV file and derive all the tests running on Linux platform with mariadb.
I did get get some answers on collecting test cases (--collect-only) can it be used to create desired CSV?, Do we have existing plugins to achieve the same?
I'm not aware of a suitable plugin (though there are hundreds of them, so it may still exist), but you can implement this yourself by implementing pytest_collection_modifyitems. You get there in the collection phase after all items are collected. The collected test items are passed there as a list, which you may use to write out the csv.
You would probably make this dependent on some option with the file name as value. Here is an example:
top-level conftest.py
This assumes that the markers to consider start with
platform_
ordb_
, you may have to adapt this, also the wanted csv format, but this should give you an idea.