Look up the pytest_assertrepr_compare hook for each test item
Before this was only done at the time the assertion plugin was loaded. This lead to counter-intuitive behaviour where two subdirectories with a pytest_assertrepr_compare hook in their conftest.py would not work, only one would ever be used. This defers assiging the _pytest.assertion.util._reprcompare function until the item is loaded (pytest_runtest_setup) so that it can use the hookrelay of the test item to find the appropriate pytest_assertrepr_compare hook for the item. This fixes issue #77.
This commit is contained in:
@@ -40,15 +40,6 @@ class TestBinReprIntegration:
|
||||
assert hook.left == [0, 1]
|
||||
assert hook.right == [0, 2]
|
||||
|
||||
def test_configure_unconfigure(self, testdir, hook):
|
||||
assert hook == util._reprcompare
|
||||
config = testdir.parseconfig()
|
||||
plugin.pytest_configure(config)
|
||||
assert hook != util._reprcompare
|
||||
from _pytest.config import pytest_unconfigure
|
||||
pytest_unconfigure(config)
|
||||
assert hook == util._reprcompare
|
||||
|
||||
def callequal(left, right):
|
||||
return plugin.pytest_assertrepr_compare('==', left, right)
|
||||
|
||||
@@ -167,6 +158,28 @@ def test_sequence_comparison_uses_repr(testdir):
|
||||
"*E*'y'*",
|
||||
])
|
||||
|
||||
@needsnewassert
|
||||
def test_assertrepr_loaded_per_dir(testdir):
|
||||
testdir.makepyfile(test_base=['def test_base(): assert 1 == 2'])
|
||||
a = testdir.mkdir('a')
|
||||
a_test = a.join('test_a.py')
|
||||
a_test.write('def test_a(): assert 1 == 2')
|
||||
a_conftest = a.join('conftest.py')
|
||||
a_conftest.write('def pytest_assertrepr_compare(): return ["summary a"]')
|
||||
b = testdir.mkdir('b')
|
||||
b_test = b.join('test_b.py')
|
||||
b_test.write('def test_b(): assert 1 == 2')
|
||||
b_conftest = b.join('conftest.py')
|
||||
b_conftest.write('def pytest_assertrepr_compare(): return ["summary b"]')
|
||||
result = testdir.runpytest()
|
||||
result.stdout.fnmatch_lines([
|
||||
'*def test_base():*',
|
||||
'*E*assert 1 == 2*',
|
||||
'*def test_a():*',
|
||||
'*E*assert summary a*',
|
||||
'*def test_b():*',
|
||||
'*E*assert summary b*'])
|
||||
|
||||
|
||||
def test_assertion_options(testdir):
|
||||
testdir.makepyfile("""
|
||||
|
||||
Reference in New Issue
Block a user