isinstance() on exception value instead of comparing types, consolidate tests
--HG-- branch : xfail-cause
This commit is contained in:
		
							parent
							
								
									7b273b8577
								
							
						
					
					
						commit
						6a4492a22d
					
				| 
						 | 
					@ -62,14 +62,11 @@ class MarkEvaluator:
 | 
				
			||||||
    def wasvalid(self):
 | 
					    def wasvalid(self):
 | 
				
			||||||
        return not hasattr(self, 'exc')
 | 
					        return not hasattr(self, 'exc')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def invalidraise(self, exctype):
 | 
					    def invalidraise(self, exc):
 | 
				
			||||||
        raises = self.get('raises')
 | 
					        raises = self.get('raises')
 | 
				
			||||||
        if not raises:
 | 
					        if not raises:
 | 
				
			||||||
            return
 | 
					            return
 | 
				
			||||||
        if isinstance(raises, tuple):
 | 
					        return not isinstance(exc, raises)
 | 
				
			||||||
            return exctype not in raises
 | 
					 | 
				
			||||||
        else:
 | 
					 | 
				
			||||||
            return raises != exctype
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def istrue(self):
 | 
					    def istrue(self):
 | 
				
			||||||
        try:
 | 
					        try:
 | 
				
			||||||
| 
						 | 
					@ -182,7 +179,7 @@ def pytest_runtest_makereport(__multicall__, item, call):
 | 
				
			||||||
        if not item.config.option.runxfail:
 | 
					        if not item.config.option.runxfail:
 | 
				
			||||||
            if evalxfail.wasvalid() and evalxfail.istrue():
 | 
					            if evalxfail.wasvalid() and evalxfail.istrue():
 | 
				
			||||||
                if call.excinfo:
 | 
					                if call.excinfo:
 | 
				
			||||||
                    if evalxfail.invalidraise(call.excinfo.type):
 | 
					                    if evalxfail.invalidraise(call.excinfo.value):
 | 
				
			||||||
                        rep.outcome = "failed"
 | 
					                        rep.outcome = "failed"
 | 
				
			||||||
                        return rep
 | 
					                        return rep
 | 
				
			||||||
                    else:
 | 
					                    else:
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -330,52 +330,27 @@ class TestXFail:
 | 
				
			||||||
            "*1 xfailed*",
 | 
					            "*1 xfailed*",
 | 
				
			||||||
        ])
 | 
					        ])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_xfail_raises_match(self, testdir):
 | 
					
 | 
				
			||||||
 | 
					    @pytest.mark.parametrize('params', [('TypeError', 'TypeError', "*1 xfailed*"),
 | 
				
			||||||
 | 
					                                        ('(AttributeError, TypeError)', 'TypeError',
 | 
				
			||||||
 | 
					                                         "*1 xfailed*"),
 | 
				
			||||||
 | 
					                                        ('TypeError', 'IndexError', "*1 failed*"),
 | 
				
			||||||
 | 
					                                        ('(AttributeError, TypeError)', 'IndexError',
 | 
				
			||||||
 | 
					                                         "*1 failed*"),
 | 
				
			||||||
 | 
					                                        ])
 | 
				
			||||||
 | 
					    def test_xfail_raises(self, params, testdir):
 | 
				
			||||||
 | 
					        expected, actual, matchline = params
 | 
				
			||||||
        p = testdir.makepyfile("""
 | 
					        p = testdir.makepyfile("""
 | 
				
			||||||
            import pytest
 | 
					            import pytest
 | 
				
			||||||
            @pytest.mark.xfail(raises=TypeError)
 | 
					            @pytest.mark.xfail(raises=%s)
 | 
				
			||||||
            def test_raises():
 | 
					            def test_raises():
 | 
				
			||||||
                raise TypeError()
 | 
					                raise %s()
 | 
				
			||||||
        """)
 | 
					        """ % (expected, actual))
 | 
				
			||||||
        result = testdir.runpytest(p)
 | 
					        result = testdir.runpytest(p)
 | 
				
			||||||
        result.stdout.fnmatch_lines([
 | 
					        result.stdout.fnmatch_lines([
 | 
				
			||||||
            "*1 xfailed*",
 | 
					            matchline,
 | 
				
			||||||
        ])
 | 
					        ])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_xfail_raises_mismatch(self, testdir):
 | 
					 | 
				
			||||||
        p = testdir.makepyfile("""
 | 
					 | 
				
			||||||
            import pytest
 | 
					 | 
				
			||||||
            @pytest.mark.xfail(raises=IndexError)
 | 
					 | 
				
			||||||
            def test_raises():
 | 
					 | 
				
			||||||
                raise TypeError()
 | 
					 | 
				
			||||||
        """)
 | 
					 | 
				
			||||||
        result = testdir.runpytest(p)
 | 
					 | 
				
			||||||
        result.stdout.fnmatch_lines([
 | 
					 | 
				
			||||||
            "*1 failed*",
 | 
					 | 
				
			||||||
        ])
 | 
					 | 
				
			||||||
    def test_xfail_raises_tuple_match(self, testdir):
 | 
					 | 
				
			||||||
        p = testdir.makepyfile("""
 | 
					 | 
				
			||||||
            import pytest
 | 
					 | 
				
			||||||
            @pytest.mark.xfail(raises=(AttributeError, TypeError))
 | 
					 | 
				
			||||||
            def test_raises():
 | 
					 | 
				
			||||||
                raise TypeError()
 | 
					 | 
				
			||||||
        """)
 | 
					 | 
				
			||||||
        result = testdir.runpytest(p)
 | 
					 | 
				
			||||||
        result.stdout.fnmatch_lines([
 | 
					 | 
				
			||||||
            "*1 xfailed*",
 | 
					 | 
				
			||||||
        ])
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    def test_xfail_raises_tuple_mismatch(self, testdir):
 | 
					 | 
				
			||||||
        p = testdir.makepyfile("""
 | 
					 | 
				
			||||||
            import pytest
 | 
					 | 
				
			||||||
            @pytest.mark.xfail(raises=(AttributeError, IndexError))
 | 
					 | 
				
			||||||
            def test_raises():
 | 
					 | 
				
			||||||
                raise TypeError()
 | 
					 | 
				
			||||||
        """)
 | 
					 | 
				
			||||||
        result = testdir.runpytest(p)
 | 
					 | 
				
			||||||
        result.stdout.fnmatch_lines([
 | 
					 | 
				
			||||||
            "*1 failed*",
 | 
					 | 
				
			||||||
        ])
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
class TestXFailwithSetupTeardown:
 | 
					class TestXFailwithSetupTeardown:
 | 
				
			||||||
    def test_failing_setup_issue9(self, testdir):
 | 
					    def test_failing_setup_issue9(self, testdir):
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue