pytest-dev / pytest-dev/pytest

Please make it possible to "mark" subtests as `xfail`

Aperta
#14,101 3 commenti 2 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Lingua principale
Python
Stelle
14.5k
Fork
3.4k
Merge medio
2g 9h
PR unite (30g)
35

Descrizione

What's the problem this feature will solve?

Currently, it isn't possible to conveniently mark a subtest as XFAIL-ing with full support for xfail_strict=True.

Describe the solution you'd like

Ideally, I'd like to be able to do something like:

def test_foo(subtests):
    with subtests.test(msg=..., xfail=condition):
        ...

that would mark this one subtest as XFAIL, the same way pytest.mark.xfail marks the whole test as XFAIL-ing.

Alternative Solutions
  1. Marking the whole test with pytest.mark.xfail causes it to unconditionally fail with xfail_strict=True. Reading the comments in the code, I infer that it isn't supported. And even if it were, more precision would be desirable.
    $ pytest test.py -v -o xfail_strict=True
    ========================================================= test session starts =========================================================
    platform linux -- Python 3.12.12, pytest-9.1.0.dev148+g0e9db5fa5, pluggy-1.6.0 -- /tmp/foo/.venv/bin/python3
    cachedir: .pytest_cache
    rootdir: /tmp/foo
    collected 1 item                                                                                                                      
    
    test.py::test_foo SUBXFAIL[xfail] (foo)                                                                                         [100%]
    test.py::test_foo FAILED                                                                                                        [100%]
    
    ============================================================== FAILURES ===============================================================
    ______________________________________________________________ test_foo _______________________________________________________________
    [XPASS(strict)] foo
    ======================================================= short test summary info =======================================================
    FAILED test.py::test_foo - [XPASS(strict)] foo
    ==================================================== 1 failed, 1 xfailed in 0.01s =====================================================
    
  2. It is possible to call pytest.xfail() directly from the test. However, this requires a bit of handiwork to "reimplement" xfail_strict.
Additional context

n/a

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia tracciando il modo in cui subtests.test, pytest.mark.xfail e pytest.xfail interagiscono con xfail_strict=True. Confronta la reportistica esistente dei subtest e il comportamento di strict-XFAIL, quindi verifica che la condizione xfail proposta per ogni subtest segnali i fallimenti attesi e i passaggi imprevisti in modalità strict senza influire sugli altri subtest.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
python
Ambito
testing-qa
Tipo di issue
Funzionalità
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Tranquilla
Chiarezza
Abbastanza chiara
Idoneità per principianti
48/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.