Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Raise an exception when "request" is used as a parametrization argument #6183

Closed
nikoskaragiannakis opened this issue Nov 13, 2019 · 1 comment · Fixed by #6184
Closed

Raise an exception when "request" is used as a parametrization argument #6183

nikoskaragiannakis opened this issue Nov 13, 2019 · 1 comment · Fixed by #6184

Comments

@nikoskaragiannakis
Copy link

I just found, accidentally, that this

@pytest.mark.parametrize('request, expected', [(1, 1)])
def test_foo(request, expected):
    assert request == expected

would raise an error

...
    def get_direct_param_fixture_func(request):
>       return request.param
E       AttributeError: 'int' object has no attribute 'param'

Wouldn't it be helpful if there was a helpful exception raised here https://github.com/pytest-dev/pytest/blob/master/src/_pytest/fixtures.py#L881-L882?

For example, if

            if argname != "request":
                fixturedef.addfinalizer(functools.partial(self.finish, request=request))
            else:
                raise ValueError('`request` cannot be use as a parametrization name')

(or a better message) in the case of the initial example gives

self = <FixtureDef name='request' scope='function' baseid=''>
request = <SubRequest 'request' for <Function 'test_foo[1-1]'>>

    def execute(self, request):
        # get required arguments and register our own finish()
        # with their finalization
        for argname in self.argnames:
            fixturedef = request._get_active_fixturedef(argname)
            if argname != "request":
                fixturedef.addfinalizer(functools.partial(self.finish, request=request))
            else:
>               raise ValueError('`request` cannot be use as a parametrization name')
E               ValueError: `request` cannot be use as a parametrization name

The pytest version i'm using is 3.10.0

@nicoddemus
Copy link
Member

Thanks @nikoskaragiannakis for the report!

nicoddemus added a commit to nicoddemus/pytest that referenced this issue Nov 13, 2019
nicoddemus added a commit to nicoddemus/pytest that referenced this issue Nov 13, 2019
nicoddemus added a commit to nicoddemus/pytest that referenced this issue Nov 13, 2019
bors bot added a commit to duckinator/bork that referenced this issue Nov 17, 2019
76: Update pytest to 5.2.4 r=duckinator a=pyup-bot


This PR updates [pytest](https://pypi.org/project/pytest) from **5.2.2** to **5.2.4**.



<details>
  <summary>Changelog</summary>
  
  
   ### 5.2.4
   ```
   =========================

Bug Fixes
---------

- `6194 &lt;https://github.com/pytest-dev/pytest/issues/6194&gt;`_: Fix incorrect discovery of non-test ``__init__.py`` files.


- `6197 &lt;https://github.com/pytest-dev/pytest/issues/6197&gt;`_: Revert &quot;The first test in a package (``__init__.py``) marked with ``pytest.mark.skip`` is now correctly skipped.&quot;.
   ```
   
  
  
   ### 5.2.3
   ```
   =========================

Bug Fixes
---------

- `5830 &lt;https://github.com/pytest-dev/pytest/issues/5830&gt;`_: The first test in a package (``__init__.py``) marked with ``pytest.mark.skip`` is now correctly skipped.


- `6099 &lt;https://github.com/pytest-dev/pytest/issues/6099&gt;`_: Fix ``--trace`` when used with parametrized functions.


- `6183 &lt;https://github.com/pytest-dev/pytest/issues/6183&gt;`_: Using ``request`` as a parameter name in ``pytest.mark.parametrize`` now produces a more
  user-friendly error.
   ```
   
  
</details>


 

<details>
  <summary>Links</summary>
  
  - PyPI: https://pypi.org/project/pytest
  - Changelog: https://pyup.io/changelogs/pytest/
  - Homepage: https://docs.pytest.org/en/latest/
</details>



Co-authored-by: pyup-bot <github-bot@pyup.io>
bors bot added a commit to rehandalal/therapist that referenced this issue Nov 19, 2019
103: Update pytest to 5.2.4 r=rehandalal a=pyup-bot


This PR updates [pytest](https://pypi.org/project/pytest) from **5.2.2** to **5.2.4**.



<details>
  <summary>Changelog</summary>
  
  
   ### 5.2.4
   ```
   =========================

Bug Fixes
---------

- `6194 &lt;https://github.com/pytest-dev/pytest/issues/6194&gt;`_: Fix incorrect discovery of non-test ``__init__.py`` files.


- `6197 &lt;https://github.com/pytest-dev/pytest/issues/6197&gt;`_: Revert &quot;The first test in a package (``__init__.py``) marked with ``pytest.mark.skip`` is now correctly skipped.&quot;.
   ```
   
  
  
   ### 5.2.3
   ```
   =========================

Bug Fixes
---------

- `5830 &lt;https://github.com/pytest-dev/pytest/issues/5830&gt;`_: The first test in a package (``__init__.py``) marked with ``pytest.mark.skip`` is now correctly skipped.


- `6099 &lt;https://github.com/pytest-dev/pytest/issues/6099&gt;`_: Fix ``--trace`` when used with parametrized functions.


- `6183 &lt;https://github.com/pytest-dev/pytest/issues/6183&gt;`_: Using ``request`` as a parameter name in ``pytest.mark.parametrize`` now produces a more
  user-friendly error.
   ```
   
  
</details>


 

<details>
  <summary>Links</summary>
  
  - PyPI: https://pypi.org/project/pytest
  - Changelog: https://pyup.io/changelogs/pytest/
  - Homepage: https://docs.pytest.org/en/latest/
</details>



Co-authored-by: pyup-bot <github-bot@pyup.io>
vinaycalastry pushed a commit to vinaycalastry/pytest that referenced this issue Dec 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants