pytest-html icon indicating copy to clipboard operation
pytest-html copied to clipboard

The report is not collecting the fail log when it's parametrized test

Open python012 opened this issue 3 years ago • 1 comments
trafficstars

Hi, I'm using conftest.py and parametrized tests, see my conftest.py

def pytest_generate_tests(metafunc):
    idlist = []
    argvalues = []
    for scenario in metafunc.cls.scenarios:
        idlist.append(scenario[0])
        items = scenario[1].items()
        argnames = [x[0] for x in items]
        argvalues.append(([x[1] for x in items]))
    metafunc.parametrize(argnames, argvalues, ids=idlist, scope="class")

a_list = [
    {
        "a": 1,
    },
    {
        "a": 2,
    },
    {
        "a": 3,
    },
]

scenarios = []

for i in range(len(a_list)):
    item = (a_list[i]["a"], {"expected": a_list[i]})
    scenarios.append(item)

and my test_cases\test_demo.py

# -*- coding: utf-8 -*-

from conftest import scenarios

class TestDemoCls(object):
    scenarios = scenarios

    def test_demo(self, expected):
        assert expected["a"] == 2

I can see console log is good.

FAILED test_cases/test_demo.py::TestDemoCls::test_demo[1] - assert 1 == 2
FAILED test_cases/test_demo.py::TestDemoCls::test_demo[3] - assert 3 == 2

But there's no fail log for failed test in the report.html

image

I just want see the fail/error log in the html report, can someone help? Thanks!

python012 avatar Sep 26 '22 03:09 python012

ok... I figure out after doing some research, it's "caused" by pytest -s, if I removed -s, just run it using pytest -v --html=report.html --self-contained-html, the failing logs are collected and displayed well, let me close this..

python012 avatar Sep 26 '22 05:09 python012