zaufi / pytest-matcher

A pytest plugin to match test output against patterns stored in files
https://pytest-matcher.readthedocs.io
2 stars 1 forks source link

feat: introduce `pm-pattern-file-fmt` configuration parameter #20

Closed zaufi closed 7 months ago

zaufi commented 8 months ago

Changes in this PR

The format string may have the following placeholders:

Default value is: {module}/{class}/{fn}{callspec}{suffix}. Set it to {class}/{fn}{callspec}{suffix} can help existing code to preserve backward compatibility broken by PR #19.

xymaxim commented 7 months ago

Could we extend a list of the placeholders with a new one, for example {dirs} or {top}, to reflect the new collection tree structure (as after pytest 8.0)? For previous versions, the value would be empty, but for latest versions it's nested directories/packages.

xymaxim commented 7 months ago

Could we extend a list of the placeholders with a new one, for example {dirs} or {top}, to reflect the new collection tree structure (as after pytest 8.0)? For previous versions, the value would be empty, but for latest versions it's nested directories/packages.

The node IDs are always resolved up to the test root directory, even if collection is started from the nested directory (in this case the displayed IDs will be relative to PWD), so the function may look like this:

def get_tree_structure(module: pytest.Module) -> str:
    parent = module.nodeid.rsplit("/", 1)[0]
    try:
        root, dirs = parent.split("/", 1)
    except ValueError:
        dirs = ""
    return dirs

collected_tree = ""
if pytest.version_tuple >= (8, 0, 0):
    collected_tree = get_tree_structure(request.parent)
zaufi commented 7 months ago

Could we extend a list of the placeholders with a new one, for example {dirs} or {top}, to reflect the new collection tree structure (as after pytest 8.0)? For previous versions, the value would be empty, but for latest versions it's nested directories/packages.

Thx! Will read about it later after merging all current PRs!