File: utils.py

package info (click to toggle)
pytest-snapshot 0.9.0-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 236 kB
  • sloc: python: 1,005; sh: 17; makefile: 16
file content (27 lines) | stat: -rw-r--r-- 1,063 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
def runpytest_with_assert_mode(testdir, request, *args):
    """
    Calls `runpytest` if possible, otherwise calls `runpytest_subprocess`.

    Calling `runpytest` when the caller is run with --assert=rewrite and the callee is run with --assert=plain
    or vice versa does not work correctly, so this wrapper calls `runpytest_subprocess` in these cases.

    Note: If you are trying to debug a test that reaches `runpytest_subprocess`, consider running the test with another
    --assert mode.
    """
    if '--assert=plain' in args:
        assert_mode = 'plain'
    elif '--assert=rewrite' in args:
        assert_mode = 'rewrite'
    else:
        raise ValueError('Use this function only if you require --assert=rewrite or --assert=plain')

    if assert_mode == request.config.option.assertmode:
        return testdir.runpytest(*args)
    else:
        return testdir.runpytest_subprocess(*args)


def assert_pytest_passes(testdir):
    result = testdir.runpytest('-v')
    result.stdout.fnmatch_lines(['*::test_sth PASSED*'])
    assert result.ret == 0