Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pytest: Test case showed as passed when fixture is failing #28

Open
danielbacara opened this issue Feb 4, 2022 · 2 comments
Open

pytest: Test case showed as passed when fixture is failing #28

danielbacara opened this issue Feb 4, 2022 · 2 comments

Comments

@danielbacara
Copy link

danielbacara commented Feb 4, 2022

Hi. First of all thank you for the sphinx-needs and sphinx-test-reports extensions. They are great and helps as to keep everything as code.

I discovered a strange behavior with pytest and sphinx-test-reports when a fixture raises an error the test cases using that fixture are still passing.

Here is a small example, which I hope is reproducible:

# test_example.py
import pytest

@pytest.fixture
def fixture_foo():
    raise Exception('ERROR on fixture')

def test_foo(fixture_foo):
    print("I'm OK")

The above test file is called using the following command:

pytest test_example.py --junitxml=junit.xml

Then in an RST file I simply call the test-report directive:

FOO
=====


.. test-report:: My Report
   :id: FOO
   :file: /workspaces/tmp/junit.xml

It's important to mention that pytest doesn't contain any additional configuration nor sphinx. Also the test suite detects that there is 1 error.

HTML Results
Test case is shown as passed
image

In the imported data, there is 1 error and one test case which is passing.
image

Packages

pytest 6.2.5
Sphinx 4.4.0
sphinx-data-viewer 0.1.2
sphinx-test-reports 0.3.6
sphinxcontrib-jsmath 1.0.1
sphinxcontrib-needs 0.7.5
sphinxcontrib-plantuml 0.22

@danwos
Copy link
Member

danwos commented Mar 31, 2023

The logic in your code to figure out the testcase status is like this:
image

So if skipped nor failiure is set as an attribute in the testcase, it must be passed.

In the given junit.xml, failure error seems to be used, so we should check our code for both values.

@TruongMinh89
Copy link

Hi,
No update for this issue?
BR,
Minh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants