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

[WIP] fixes #3664 #4113

Closed
wants to merge 0 commits into from
Closed

[WIP] fixes #3664 #4113

wants to merge 0 commits into from

Conversation

avirlrma
Copy link
Contributor

fixes #3664.
for now, I was able to get an exception when we apply a fixture to an already marked function. But the output of the same is not very pretty.

(ok-SmhP-Aw1) xx@dell:~/ok/pytest$ pytest ../test_fix_mark.py 
======================================================================================= test session starts ========================================================================================
platform linux -- Python 3.6.5, pytest-3.8.2.dev38+g25fe3706, py-1.6.0, pluggy-0.7.1
rootdir: /home/xx/ok, inifile:
collected 1 item                                                                                                                                                                                   

../test_fix_mark.py E                                                                                                                                                                        [100%]

============================================================================================== ERRORS ==============================================================================================
_____________________________________________________________________________________ ERROR at setup of test_a _____________________________________________________________________________________

self = <CallInfo when='setup' exception: i did it!>, func = <function call_runtest_hook.<locals>.<lambda> at 0x7f7327859158>, when = 'setup', treat_keyboard_interrupt_as_exception = False

    def __init__(self, func, when, treat_keyboard_interrupt_as_exception=False):
        #: context of invocation: one of "setup", "call",
        #: "teardown", "memocollect"
        self.when = when
        self.start = time()
        try:
>           self.result = func()

src/_pytest/runner.py:201: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
src/_pytest/runner.py:183: in <lambda>
    lambda: ihook(item=item, **kwds),
../../.local/share/virtualenvs/ok-SmhP-Aw1/lib/python3.6/site-packages/pluggy/hooks.py:258: in __call__
    return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
../../.local/share/virtualenvs/ok-SmhP-Aw1/lib/python3.6/site-packages/pluggy/manager.py:67: in _hookexec
    return self._inner_hookexec(hook, methods, kwargs)
../../.local/share/virtualenvs/ok-SmhP-Aw1/lib/python3.6/site-packages/pluggy/manager.py:61: in <lambda>
    firstresult=hook.spec_opts.get('firstresult'),
src/_pytest/runner.py:104: in pytest_runtest_setup
    item.session._setupstate.prepare(item)
src/_pytest/runner.py:370: in prepare
    col.setup()
src/_pytest/python.py:1463: in setup
    fixtures.fillfixtures(self)
src/_pytest/fixtures.py:294: in fillfixtures
    request._fillfixtures()
src/_pytest/fixtures.py:467: in _fillfixtures
    item.funcargs[argname] = self.getfixturevalue(argname)
src/_pytest/fixtures.py:511: in getfixturevalue
    return self._get_active_fixturedef(argname).cached_result[0]
src/_pytest/fixtures.py:534: in _get_active_fixturedef
    self._compute_fixture_value(fixturedef)
src/_pytest/fixtures.py:620: in _compute_fixture_value
    fixturedef.execute(request=subrequest)
src/_pytest/fixtures.py:913: in execute
    return hook.pytest_fixture_setup(fixturedef=self, request=request)
../../.local/share/virtualenvs/ok-SmhP-Aw1/lib/python3.6/site-packages/pluggy/hooks.py:258: in __call__
    return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
../../.local/share/virtualenvs/ok-SmhP-Aw1/lib/python3.6/site-packages/pluggy/manager.py:67: in _hookexec
    return self._inner_hookexec(hook, methods, kwargs)
../../.local/share/virtualenvs/ok-SmhP-Aw1/lib/python3.6/site-packages/pluggy/manager.py:61: in <lambda>
    firstresult=hook.spec_opts.get('firstresult'),
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

fixturedef = <FixtureDef name='user_tom' scope='function' baseid='test_fix_mark.py' >, request = <SubRequest 'user_tom' for <Function 'test_a'>>

    def pytest_fixture_setup(fixturedef, request):
        """ Execution of fixture setup. """
        kwargs = {}
        for argname in fixturedef.argnames:
            fixdef = request._get_active_fixturedef(argname)
            result, arg_cache_key, exc = fixdef.cached_result
            request._check_scope(argname, request.scope, fixdef.scope)
            kwargs[argname] = result
    
        fixturefunc = resolve_fixture_function(fixturedef, request)
        if hasattr(fixturefunc,'pytestmark'):
>           raise Exception('i did it!')
E           Exception: i did it!

src/_pytest/fixtures.py:954: Exception

I will try to make this right.

@@ -950,6 +950,8 @@ def pytest_fixture_setup(fixturedef, request):
kwargs[argname] = result

fixturefunc = resolve_fixture_function(fixturedef, request)
if hasattr(fixturefunc,'pytestmark'):
raise Exception('i did it!')
Copy link
Member

Choose a reason for hiding this comment

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

Use fail(msg, pytrace=False) instead. 😁

Also this should go into features, as it might break functional (but incorrect) test suites.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oh thanks @nicoddemus.
so the course of action will be:

  • move to features.
  • correct the error invokation.
  • write tests for this.
  • then work on the other half
    right?

Copy link
Member

Choose a reason for hiding this comment

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

Correct. Thanks for tackling this! 👍

@nicoddemus nicoddemus changed the title fixes #3664 [WIP] fixes #3664 Oct 11, 2018
@avirlrma avirlrma closed this Oct 12, 2018
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.

Generate an error when a mark is applied to a fixture
2 participants