Skip to content

deprecate raises(..., code_string) #4435

@asottile

Description

@asottile

Very minor, but strange -- it would be better if it used the line that it was called from:

import pytest


def test():
    s = "qwe"  # NOQA
    pytest.raises(TypeError, "int(s)")
$ ./venv/bin/pytest t.py 
============================= test session starts ==============================
platform linux -- Python 3.6.6, pytest-4.0.0, py-1.7.0, pluggy-0.8.0
rootdir: /tmp/t, inifile:
collected 1 item                                                               

t.py F                                                                   [100%]

=================================== FAILURES ===================================
_____________________________________ test _____________________________________

    def test():
        s = "qwe"  # NOQA
>       pytest.raises(TypeError, "int(s)")

t.py:6: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

>   int(s)
E   ValueError: invalid literal for int() with base 10: 'qwe'

<0-codegen /tmp/t/venv/lib/python3.6/site-packages/_pytest/python_api.py:682>:1: ValueError
=========================== 1 failed in 0.03 seconds ===========================

Or maybe we should deprecate this form of raises, execing code seems... less than ideal

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: backward compatibilitymight present some backward compatibility issues which should be carefully noted in the changelogtype: deprecationfeature that will be removed in the future

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions