pytest-dev / pytest-dev/pytest

[RFC] Explicit mechanism for supporting xfail and skip in [third-party] plugins

Open
#7,327 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

status: help wanted type: docs type: proposal
Dominant language
Python
Stars
14.5k
Forks
3.4k
Avg merge
2d 9h
Merged PRs (30d)
35

Description

While working on https://github.com/pytest-dev/pytest-forked/pull/34 I had to go through source code in the skipping plugin to figure out how to make pytest show xfailed tests for runs made by an external plugin. And here's my observations:

  1. It's undocumented how to integrate xfail with test reports from plugins.
  2. I learned that if you set outcome='xfailed' and wasxfail = 'reason', pytest will show normal xfailed output in the failures and summary sections but the progress section will show the failure (F letter instead of X/x).
  3. I discovered that I have to set outcome='skipped' (along with wasxfail = 'reason'!) to make it show consistent output but I need to set it only if I discover that the test has xfail marker. Wait, what? skipped? Really? But I really ran it...
  4. I need to inspect all the marks and their conditionals. I need to figure out if the conditional expression of any mark is true or it raises the expected exception.
  5. Internal implementation details leak into the public API... (at least this is how I see the need to set certain magic combination of values and do manual condition matching)

So here's what I think could be improved:

  1. Docs. It should be explicitly documented how to make your plugin work with xfail.
  2. There could be some sort of public API to make the test result xfailed. (I don't really like this so see (3))
  3. Implement a better xfail processing mechanism on the pytest internals side.
    • Plugins should cleanly report failures and passes
    • pytest should convert the test reports to have proper attributes related to xfail after receiving results from plugins
    • There should be a mechanism to convey an exception that caused the failure in the test run from plugin to pytest so that it could also match it against the raises arg

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading the skipping plugin behavior and the external-plugin integration described through pytest-forked#34, focusing on test reports, xfail markers, conditional expressions, and the raises argument. The issue proposes documentation, a public API, or internal report conversion; done would require choosing and specifying one approach that gives plugins consistent xfail and skip output.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
testing-qa
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.