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

Always lstrip() keyword expression #1500

Merged
merged 1 commit into from
Apr 1, 2016

Conversation

goodboy
Copy link

@goodboy goodboy commented Apr 1, 2016

This solves the following bug.
Given and example test mod test_name_filter.py:

def test_4x4():                
    pass                       

if __name__ == '__main__':     
    import pytest              
    pytest.main(["-k not 4x4"])

Running from an IPython shell:

In [26]: run ./test_name_filter.py                                                                           
================================================= test session starts =======================================
platform linux2 -- Python 2.7.11, pytest-2.9.0, py-1.4.31, pluggy-0.3.1
rootdir: /home/tyler/pytest_bugs, inifile: 
plugins: interactive-0.1.1, ordering-0.4, instafail-0.3.0
collected 1 items 
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR>   File "/home/tyler/repos/pytest/_pytest/main.py", line 94, in wrap_session
INTERNALERROR>     session.exitstatus = doit(config, session) or 0
INTERNALERROR>   File "/home/tyler/repos/pytest/_pytest/main.py", line 124, in _main
INTERNALERROR>     config.hook.pytest_collection(session=session)
INTERNALERROR>   File "/home/tyler/repos/pytest/_pytest/vendored_packages/pluggy.py", line 724, in __call__
INTERNALERROR>     return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
INTERNALERROR>   File "/home/tyler/repos/pytest/_pytest/vendored_packages/pluggy.py", line 338, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR>   File "/home/tyler/repos/pytest/_pytest/vendored_packages/pluggy.py", line 333, in <lambda>
INTERNALERROR>     _MultiCall(methods, kwargs, hook.spec_opts).execute()
INTERNALERROR>   File "/home/tyler/repos/pytest/_pytest/vendored_packages/pluggy.py", line 596, in execute
INTERNALERROR>     res = hook_impl.function(*args)
INTERNALERROR>   File "/home/tyler/repos/pytest/_pytest/main.py", line 133, in pytest_collection
INTERNALERROR>     return session.perform_collect()
INTERNALERROR>   File "/home/tyler/repos/pytest/_pytest/main.py", line 567, in perform_collect
INTERNALERROR>     config=self.config, items=items)
INTERNALERROR>   File "/home/tyler/repos/pytest/_pytest/vendored_packages/pluggy.py", line 724, in __call__
INTERNALERROR>     return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
INTERNALERROR>   File "/home/tyler/repos/pytest/_pytest/vendored_packages/pluggy.py", line 338, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR>   File "/home/tyler/repos/pytest/_pytest/vendored_packages/pluggy.py", line 333, in <lambda>
INTERNALERROR>     _MultiCall(methods, kwargs, hook.spec_opts).execute()
INTERNALERROR>   File "/home/tyler/repos/pytest/_pytest/vendored_packages/pluggy.py", line 596, in execute
INTERNALERROR>     res = hook_impl.function(*args)
INTERNALERROR>   File "/home/tyler/repos/pytest/_pytest/mark.py", line 78, in pytest_collection_modifyitems
INTERNALERROR>     if keywordexpr and not matchkeyword(colitem, keywordexpr):
INTERNALERROR>   File "/home/tyler/repos/pytest/_pytest/mark.py", line 161, in matchkeyword
INTERNALERROR>     return eval(keywordexpr, {}, mapping)
INTERNALERROR>   File "<string>", line 1
INTERNALERROR>     not 4x4
INTERNALERROR>           ^
INTERNALERROR> SyntaxError: unexpected EOF while parsing

============================================ no tests ran in 0.00 seconds ===================================

It will also be triggered from the console if a user mistakenly prefixes the expression with a space:

$ py.test ./test_filter_name -k ' not 4x4'

I wasn't sure if the change warranted a test but I added quick one anyway.
Also I figured this was too trivial to add to AUTHORS or CHANGELOG.

@nicoddemus nicoddemus merged commit 5af5ba1 into pytest-dev:master Apr 1, 2016
@nicoddemus
Copy link
Member

Thanks! 😄

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.

2 participants