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

Issue 460: Fail on getfuncargvalue(<fixture with params>) #1620

Merged

Conversation

tomviner
Copy link
Contributor

@tomviner tomviner commented Jun 20, 2016

Fix for #460

Raise helpful failure message, when requesting parametrized fixture at runtime, e.g. with request.getfuncargvalue.

This now fails before getting to AttributeError: 'SubRequest' object has no attribute 'param'.

BACKWARD INCOMPAT: Previously these params were simply never defined. So a fixture decorated like @pytest.fixture(params=[0, 1, 2]) only runs once. Now a failure is raised.

if fixturedef.params is not None:
curdir = py.path.local()
frame = inspect.stack()[3]
_, source_path, source_lineno, _, _, _ = frame
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

source-path should be relative to the test root if possible

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems kind of weird - if I'm reading the docs correctly you can do inspect.getframeinfo(frame) and then have a namedtuple with filename and lineno attributes.

@coveralls
Copy link

coveralls commented Jun 20, 2016

Coverage Status

Coverage increased (+0.005%) to 92.211% when pulling 435d68a on tomviner:issue460/parameterized-subrequest into d81ee9a on pytest-dev:master.

E*Failed: The requested fixture has no parameter defined for the current test.
E*
E*Requested fixture 'fix_with_param' defined in:
E*{}:4
Copy link
Member

@nicoddemus nicoddemus Jun 21, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not valid in py26, that's why CI failed. 😉

@tomviner tomviner force-pushed the issue460/parameterized-subrequest branch from 435d68a to e5e91af Compare June 21, 2016 09:18
@coveralls
Copy link

coveralls commented Jun 21, 2016

Coverage Status

Coverage increased (+0.009%) to 92.214% when pulling e5e91af on tomviner:issue460/parameterized-subrequest into 5d8d1db on pytest-dev:master.

@tomviner
Copy link
Contributor Author

Added the commented changes

  • used named tuple from inspect.getframeinfo
  • made path relative to root dir and added test
  • fixed python 2.6 .format needed {0}
  • changed change log entry

@tomviner tomviner force-pushed the issue460/parameterized-subrequest branch from e5e91af to 5854a71 Compare June 21, 2016 09:29
@coveralls
Copy link

coveralls commented Jun 21, 2016

Coverage Status

Coverage increased (+0.009%) to 92.214% when pulling 5854a71 on tomviner:issue460/parameterized-subrequest into 5d8d1db on pytest-dev:master.

@The-Compiler
Copy link
Member

LGTM, but I'd rather not be the one deciding on the backwards compatibility break and if it's okay 😆 - as said, I think it's perfectly fine for 3.0.

@nicoddemus
Copy link
Member

be the one deciding on the backwards compatibility break and if it's okay

Hmm which backward compatibility break?

@tomviner
Copy link
Contributor Author

tomviner commented Jun 21, 2016

@The-Compiler @nicoddemus

be the one deciding on the backwards compatibility break and if it's okay

Hmm which backward compatibility break?

The fact that this previously silently failed to apply the params:

@pytest.fixture(params=[0, 1, 2])
def fix_with_param(request):
    print "I never call request.param"

def test_foo(request):
    request.getfuncargvalue('fix_with_param')

And now fails with the helpful error message.

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 this pull request may close these issues.

5 participants