I'm playing with the idea of returning a custom explanation for tests with a particular marker but returning Pytest's standard explanation for tests without the marker.
I was hoping to do something like this... # content of conftest.py def pytest_assertrepr_compare(config, op, left, right): if <current test uses "mymark">: return ['My custom explanation!'] # content of test_mystuff.py import pytest def test_mystuff1(): assert 100 == 105 @pytest.mark.mymark def test_mystuff2(): assert 100 == 105 # Desired Output __________ test_mystuff1 __________ def test_mystuff1(): > assert 100 == 105 E assert 100 == 105 E -100 E +105 test_mystuff.py:4: AssertionError __________ test_mystuff2 __________ @pytest.mark.mymark def test_mystuff2(): > assert 100 == 105 E assert My custom explanation! test_mystuff.py:8: AssertionError I've looked through the plugin API but I don't see a straightforward way of doing this. I was hoping I could get a reference to the current test through the config (even if it was a convoluted reference) but I don't know if this is possible. Digging deeper, I see some undesirable approaches I could probably use to accomplish this (e.g., monkey-patch util._reprcompare or possibly maintain a plugin-level global that points to the current test) but nothing that seems to work with the grain of the plugin API. So I have a few related questions I'm hoping someone can help me with: Q: Is there a way to reference the current test from within pytest_assertrepr_compare()? Q: If not, is there a decent way to implement something like this that isn't too hacky?
_______________________________________________ pytest-dev mailing list pytest-dev@python.org https://mail.python.org/mailman/listinfo/pytest-dev