Code Monkey home page Code Monkey logo

Comments (7)

okken avatar okken commented on June 5, 2024

Example code exhibiting the problem:

import pytest_check as check
import pytest

@pytest.mark.xfail()
def test_fail_check():
    check.equal(1, 2)

Note: I did verify that the code works with pytest 5.3.5.
It was the pytest 5.4.0 update that caused the failure

from pytest-check.

okken avatar okken commented on June 5, 2024

The code in question is probably the pytest_runtest_makereport() hook:

@pytest.hookimpl(hookwrapper=True, trylast=True)
def pytest_runtest_makereport(item, call):
    outcome = yield
    report = outcome.get_result()
    evalxfail = getattr(item, "_evalxfail", None)
    failures = check_methods.get_failures()
    check_methods.clear_failures()

    if failures:
        if evalxfail and evalxfail.wasvalid() and evalxfail.istrue():
            report.outcome = "skipped"
            report.wasxfail = evalxfail.getexplanation()
        elif outcome._result.longreprtext.startswith("[XPASS(strict)]"):
            report.outcome = "skipped"
            report.wasxfail = "\n".join(failures)
        else:
            summary = "Failed Checks: {}".format(len(failures))
            longrepr = ["\n".join(failures)]
            longrepr.append("-" * 60)
            longrepr.append(summary)
            report.longrepr = "\n".join(longrepr)
            report.outcome = "failed"

This is where I'm setting failue, xfail, etc.
My guess is the format of the _evalxfail object may have changed.

from pytest-check.

okken avatar okken commented on June 5, 2024

Ok. well, now that I pinpoint where I'm abusing the pytest internals manipulate the results, I'm not surprised that relying on _evalxfail and _result eventually broke.
This will take some head scratching to solve.

May be prudent to simplify this plugin and state that xfail isn't supported.

from pytest-check.

asottile avatar asottile commented on June 5, 2024

this is definitely something that I think should be exposed by pytest to plugins, but I'm not quite sure how at the moment 🤔

here's an UGLY workaround (which really just restores the access this plugin was doing before)

try:
    evalxfail = item._evalxfail
except AttributeError:
    from _pytest.skipping import evalxfail_key
    evalxfail = item._store[evalxfail_key]

from pytest-check.

okken avatar okken commented on June 5, 2024

thank you!

from pytest-check.

dillonm197 avatar dillonm197 commented on June 5, 2024

I'm not sure if this is reliable but you may be able to loop through the report object's keyword dict and look for the xfail key. The keyword should show up if xfail is added programmatically or with pytest.mark.xfail. This also would eliminate the use of protected objects.

from pytest-check.

okken avatar okken commented on June 5, 2024

I like this idea. I'll try it sometime soon-ish.
For now, I'll close this with the workaround in place

from pytest-check.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.