Move everything unnecessary out of pytest.raises context