简体   繁体   中英

How can I see more information about the failed test cases in the pytest?

import subprocess
import pytest

@pytest.mark.parametrize("x", range(19))
@pytest.mark.parametrize("y", range(3))
def test_fw(x, y):   
     subprocess.call(['fw-test.exe', '--cal_tank', str(x), str(y)])

An example from output: I have some errors. How can I know how much they are?

.ERROR : Provided invalid 'mode' argument (17). Valid range from 0 to 16.
Usage:
--cal_tank mode rcv_index [output_csv_file]
.ERROR : Provided invalid 'mode' argument (18). Valid range from 0 to 16.
Usage:
--cal_tank mode rcv_index [output_csv_file]



========================== 57 passed in 7.78 seconds ==========================
# To call:
#  python -m pytest ppp.py

import pytest
from subprocess import *

FWTEST_PATH = r'fw-test.exe' # Here should be full path to the fw-test.exe !

def call_fwtest(x, y, timeout=3):
    with Popen([FWTEST_PATH, '--cal_tank', str(x), str(y)],
            stderr=PIPE, stdout=PIPE) as p:
        p.wait(timeout)
        return (p.returncode, p.stderr.read(), p.stdout.read())

@pytest.mark.parametrize("x", range(19))
@pytest.mark.parametrize("y", range(3))
def test_fw(x, y):
    returncode, out, err = call_fwtest(x, y)
    assert out == b'MY EXPECTED OUT'

You can set timeout argument to control the time after which you will get TimeoutExpired exception if the command fw-test.exe hungs up. To call it use command line python3 -m pytest ppp.py where "ppp.py" is supposed name of this file. Read more here about used functions of the "subprocess" module. Output is of type bytes, if you need, you can add encoding parameter to the Popen call.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM