Merge pull request #2284 from omerhadari/bugfix-unprintable-assertion-errors
Bugfix unprintable assertion errors
This commit is contained in:
		
						commit
						b28749eb92
					
				
							
								
								
									
										1
									
								
								AUTHORS
								
								
								
								
							
							
						
						
									
										1
									
								
								AUTHORS
								
								
								
								
							| 
						 | 
					@ -113,6 +113,7 @@ Nicolas Delaby
 | 
				
			||||||
Oleg Pidsadnyi
 | 
					Oleg Pidsadnyi
 | 
				
			||||||
Oliver Bestwalter
 | 
					Oliver Bestwalter
 | 
				
			||||||
Omar Kohl
 | 
					Omar Kohl
 | 
				
			||||||
 | 
					Omer Hadari
 | 
				
			||||||
Patrick Hayes
 | 
					Patrick Hayes
 | 
				
			||||||
Pieter Mulder
 | 
					Pieter Mulder
 | 
				
			||||||
Piotr Banaszkiewicz
 | 
					Piotr Banaszkiewicz
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -22,7 +22,8 @@
 | 
				
			||||||
* Replace ``raise StopIteration`` usages in the code by simple ``returns`` to finish generators, in accordance to `PEP-479`_ (`#2160`_).
 | 
					* Replace ``raise StopIteration`` usages in the code by simple ``returns`` to finish generators, in accordance to `PEP-479`_ (`#2160`_).
 | 
				
			||||||
  Thanks `@tgoodlet`_ for the report and `@nicoddemus`_ for the PR.
 | 
					  Thanks `@tgoodlet`_ for the report and `@nicoddemus`_ for the PR.
 | 
				
			||||||
  
 | 
					  
 | 
				
			||||||
*  
 | 
					* Fix internal errors when an unprintable ``AssertionError`` is raised inside a test.
 | 
				
			||||||
 | 
					  Thanks `@omerhadari`_ for the PR.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
* Skipping plugin now also works with test items generated by custom collectors (`#2231`_).
 | 
					* Skipping plugin now also works with test items generated by custom collectors (`#2231`_).
 | 
				
			||||||
  Thanks to `@vidartf`_.
 | 
					  Thanks to `@vidartf`_.
 | 
				
			||||||
| 
						 | 
					@ -42,6 +43,7 @@
 | 
				
			||||||
.. _@sirex: https://github.com/sirex
 | 
					.. _@sirex: https://github.com/sirex
 | 
				
			||||||
.. _@vidartf: https://github.com/vidartf
 | 
					.. _@vidartf: https://github.com/vidartf
 | 
				
			||||||
.. _@kkoukiou: https://github.com/KKoukiou
 | 
					.. _@kkoukiou: https://github.com/KKoukiou
 | 
				
			||||||
 | 
					.. _@omerhadari: https://github.com/omerhadari
 | 
				
			||||||
 | 
					
 | 
				
			||||||
.. _#2248: https://github.com/pytest-dev/pytest/issues/2248
 | 
					.. _#2248: https://github.com/pytest-dev/pytest/issues/2248
 | 
				
			||||||
.. _#2137: https://github.com/pytest-dev/pytest/issues/2137
 | 
					.. _#2137: https://github.com/pytest-dev/pytest/issues/2137
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -352,6 +352,8 @@ class ExceptionInfo(object):
 | 
				
			||||||
        help for navigating the traceback.
 | 
					        help for navigating the traceback.
 | 
				
			||||||
    """
 | 
					    """
 | 
				
			||||||
    _striptext = ''
 | 
					    _striptext = ''
 | 
				
			||||||
 | 
					    _assert_start_repr = "AssertionError(u\'assert " if sys.version_info[0] < 3 else "AssertionError(\'assert "
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def __init__(self, tup=None, exprinfo=None):
 | 
					    def __init__(self, tup=None, exprinfo=None):
 | 
				
			||||||
        import _pytest._code
 | 
					        import _pytest._code
 | 
				
			||||||
        if tup is None:
 | 
					        if tup is None:
 | 
				
			||||||
| 
						 | 
					@ -359,8 +361,8 @@ class ExceptionInfo(object):
 | 
				
			||||||
            if exprinfo is None and isinstance(tup[1], AssertionError):
 | 
					            if exprinfo is None and isinstance(tup[1], AssertionError):
 | 
				
			||||||
                exprinfo = getattr(tup[1], 'msg', None)
 | 
					                exprinfo = getattr(tup[1], 'msg', None)
 | 
				
			||||||
                if exprinfo is None:
 | 
					                if exprinfo is None:
 | 
				
			||||||
                    exprinfo = py._builtin._totext(tup[1])
 | 
					                    exprinfo = py.io.saferepr(tup[1])
 | 
				
			||||||
                if exprinfo and exprinfo.startswith('assert '):
 | 
					                if exprinfo and exprinfo.startswith(self._assert_start_repr):
 | 
				
			||||||
                    self._striptext = 'AssertionError: '
 | 
					                    self._striptext = 'AssertionError: '
 | 
				
			||||||
        self._excinfo = tup
 | 
					        self._excinfo = tup
 | 
				
			||||||
        #: the exception class
 | 
					        #: the exception class
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -916,6 +916,25 @@ def test_assert_with_unicode(monkeypatch, testdir):
 | 
				
			||||||
    result = testdir.runpytest()
 | 
					    result = testdir.runpytest()
 | 
				
			||||||
    result.stdout.fnmatch_lines(['*AssertionError*'])
 | 
					    result.stdout.fnmatch_lines(['*AssertionError*'])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def test_raise_unprintable_assertion_error(testdir):
 | 
				
			||||||
 | 
					    testdir.makepyfile(r"""
 | 
				
			||||||
 | 
					        def test_raise_assertion_error():
 | 
				
			||||||
 | 
					            raise AssertionError('\xff')
 | 
				
			||||||
 | 
					    """)
 | 
				
			||||||
 | 
					    result = testdir.runpytest()
 | 
				
			||||||
 | 
					    result.stdout.fnmatch_lines([r">       raise AssertionError('\xff')", 'E       AssertionError: *'])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def test_raise_assertion_error_raisin_repr(testdir):
 | 
				
			||||||
 | 
					    testdir.makepyfile(u"""
 | 
				
			||||||
 | 
					        class RaisingRepr(object):
 | 
				
			||||||
 | 
					            def __repr__(self):
 | 
				
			||||||
 | 
					                raise Exception()
 | 
				
			||||||
 | 
					        def test_raising_repr():
 | 
				
			||||||
 | 
					            raise AssertionError(RaisingRepr())
 | 
				
			||||||
 | 
					    """)
 | 
				
			||||||
 | 
					    result = testdir.runpytest()
 | 
				
			||||||
 | 
					    result.stdout.fnmatch_lines(['E       AssertionError: <unprintable AssertionError object>'])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def test_issue_1944(testdir):
 | 
					def test_issue_1944(testdir):
 | 
				
			||||||
    testdir.makepyfile("""
 | 
					    testdir.makepyfile("""
 | 
				
			||||||
        def f():
 | 
					        def f():
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue