Merge pull request #12027 from bluetech/sys-last-exc
runner: add support for `sys.last_exc` for post-mortem debugging on Python>=3.12
This commit is contained in:
		
						commit
						a2a9aa6cde
					
				
							
								
								
									
										1
									
								
								AUTHORS
								
								
								
								
							
							
						
						
									
										1
									
								
								AUTHORS
								
								
								
								
							| 
						 | 
					@ -128,6 +128,7 @@ Edison Gustavo Muenz
 | 
				
			||||||
Edoardo Batini
 | 
					Edoardo Batini
 | 
				
			||||||
Edson Tadeu M. Manoel
 | 
					Edson Tadeu M. Manoel
 | 
				
			||||||
Eduardo Schettino
 | 
					Eduardo Schettino
 | 
				
			||||||
 | 
					Edward Haigh
 | 
				
			||||||
Eero Vaher
 | 
					Eero Vaher
 | 
				
			||||||
Eli Boyarski
 | 
					Eli Boyarski
 | 
				
			||||||
Elizaveta Shashkova
 | 
					Elizaveta Shashkova
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1 @@
 | 
				
			||||||
 | 
					Added support for :data:`sys.last_exc` for post-mortem debugging on Python>=3.12.
 | 
				
			||||||
| 
						 | 
					@ -164,6 +164,8 @@ def pytest_runtest_call(item: Item) -> None:
 | 
				
			||||||
        del sys.last_type
 | 
					        del sys.last_type
 | 
				
			||||||
        del sys.last_value
 | 
					        del sys.last_value
 | 
				
			||||||
        del sys.last_traceback
 | 
					        del sys.last_traceback
 | 
				
			||||||
 | 
					        if sys.version_info >= (3, 12, 0):
 | 
				
			||||||
 | 
					            del sys.last_exc  # type: ignore[attr-defined]
 | 
				
			||||||
    except AttributeError:
 | 
					    except AttributeError:
 | 
				
			||||||
        pass
 | 
					        pass
 | 
				
			||||||
    try:
 | 
					    try:
 | 
				
			||||||
| 
						 | 
					@ -172,6 +174,8 @@ def pytest_runtest_call(item: Item) -> None:
 | 
				
			||||||
        # Store trace info to allow postmortem debugging
 | 
					        # Store trace info to allow postmortem debugging
 | 
				
			||||||
        sys.last_type = type(e)
 | 
					        sys.last_type = type(e)
 | 
				
			||||||
        sys.last_value = e
 | 
					        sys.last_value = e
 | 
				
			||||||
 | 
					        if sys.version_info >= (3, 12, 0):
 | 
				
			||||||
 | 
					            sys.last_exc = e  # type: ignore[attr-defined]
 | 
				
			||||||
        assert e.__traceback__ is not None
 | 
					        assert e.__traceback__ is not None
 | 
				
			||||||
        # Skip *this* frame
 | 
					        # Skip *this* frame
 | 
				
			||||||
        sys.last_traceback = e.__traceback__.tb_next
 | 
					        sys.last_traceback = e.__traceback__.tb_next
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -926,6 +926,9 @@ def test_store_except_info_on_error() -> None:
 | 
				
			||||||
    # Check that exception info is stored on sys
 | 
					    # Check that exception info is stored on sys
 | 
				
			||||||
    assert sys.last_type is IndexError
 | 
					    assert sys.last_type is IndexError
 | 
				
			||||||
    assert isinstance(sys.last_value, IndexError)
 | 
					    assert isinstance(sys.last_value, IndexError)
 | 
				
			||||||
 | 
					    if sys.version_info >= (3, 12, 0):
 | 
				
			||||||
 | 
					        assert isinstance(sys.last_exc, IndexError)  # type: ignore[attr-defined]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    assert sys.last_value.args[0] == "TEST"
 | 
					    assert sys.last_value.args[0] == "TEST"
 | 
				
			||||||
    assert sys.last_traceback
 | 
					    assert sys.last_traceback
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -934,6 +937,8 @@ def test_store_except_info_on_error() -> None:
 | 
				
			||||||
    runner.pytest_runtest_call(ItemMightRaise())  # type: ignore[arg-type]
 | 
					    runner.pytest_runtest_call(ItemMightRaise())  # type: ignore[arg-type]
 | 
				
			||||||
    assert not hasattr(sys, "last_type")
 | 
					    assert not hasattr(sys, "last_type")
 | 
				
			||||||
    assert not hasattr(sys, "last_value")
 | 
					    assert not hasattr(sys, "last_value")
 | 
				
			||||||
 | 
					    if sys.version_info >= (3, 12, 0):
 | 
				
			||||||
 | 
					        assert not hasattr(sys, "last_exc")
 | 
				
			||||||
    assert not hasattr(sys, "last_traceback")
 | 
					    assert not hasattr(sys, "last_traceback")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue