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

show a simple and easy error when keyword expressions trigger a syntax error #2953

Closed
eode opened this issue Nov 26, 2017 · 9 comments
Closed
Labels
good first issue easy issue that is friendly to new contributor topic: reporting related to terminal output and user-facing messages and errors type: enhancement new feature or API change, should be merged into features branch type: feature-branch new feature or API change, should be merged into features branch

Comments

@eode
Copy link

eode commented Nov 26, 2017

Submitted this too early, it's been edited to fix.

Expected behavior:
Either: It doesn't matter if you name a search expression that includes a python keyword
Or: A warning not to use python keywords is given instead of an INTERNALERROR.

Actual behavior:
If a search term is a python keyword is given, an INTERNALERROR is caused by a SyntaxError exception.

Specifically, this works:
pytest -k <python keyword>

but this does not:
pytest -k 'something or <python keyword>

Examples with no problem:

pytest -k "command or mport"
pytest -k "mport or command"
pytest -k "command or fi"

Examples with a problem

pytest -k "command or import"
pytest -k "import or command"
pytest -k "command or if"

pip list:
alabaster (0.7.8)
apparmor (2.10.95)
appdirs (1.4.3)
apt-xapian-index (0.47)
apturl (0.5.2)
argcomplete (0.8.1)
argh (0.26.1)
asn1crypto (0.23.0)
astroid (1.4.5)
attrs (17.3.0)
Automat (0.6.0)
Babel (2.3.4)
backports.shutil-get-terminal-size (1.0.0)
beautifulsoup4 (4.4.1)
blessings (1.6)
blinker (1.3)
blist (1.3.6)
bpython (0.15)
Brlapi (0.6.4)
certifi (2017.11.5)
cffi (1.11.2)
chardet (3.0.4)
checkbox-ng (0.23)
checkbox-support (0.22)
chrome-gnome-shell (0.0.0)
click (6.6)
colorama (0.3.7)
command-not-found (0.3)
constantly (15.1.0)
cookies (2.2.1)
coreapi (2.3.1)
coreapi-cli (1.0.6)
coreschema (0.0.4)
cryptography (2.1.3)
curtsies (0.2.6)
cycler (0.9.0)
decorator (4.0.9)
defer (1.0.6)
devscripts (2.16.2ubuntu3)
dill (0.2.7.1)
distribute (0.7.3)
distro (1.0.4)
docopt (0.6.2)
docutils (0.12)
entrypoints (0.2.2)
exofrills (0.1.12)
feedparser (5.1.3)
flake8 (3.4.1)
flake8-docstrings (1.1.0)
flake8-polyfill (1.0.1)
future (0.16.0)
greenlet (0.4.9)
guacamole (0.9.2)
haxor-news (0.4.1)
html5lib (0.999)
httplib2 (0.9.1)
hyperlink (17.3.1)
idna (2.6)
imagesize (0.7.1)
incremental (17.5.0)
ipykernel (4.3.1)
ipython (4.2.0)
ipython-genutils (0.1.0)
itypes (1.1.0)
jedi (0.10.2)
Jinja2 (2.8)
jsonschema (2.5.1)
jupyter-client (4.2.2)
jupyter-core (4.1.0)
language-selector (0.1)
lazy-object-proxy (1.2.2)
LibAppArmor (2.10.95)
lightdm-gtk-greeter-settings (1.2.1)
louis (2.6.4)
lxml (3.5.0)
Magic-file-extensions (0.2)
Mako (1.0.3)
MarkupSafe (0.23)
matplotlib (1.5.1)
mccabe (0.6.1)
MinimalModbus (0.7)
mistune (0.7.2)
modbus-tk (0.5.8)
multiprocess (0.70.5)
nbconvert (4.2.0)
nbformat (4.0.1)
networkx (1.11)
nose (1.3.7)
npyscreen (4.10.5)
numexpr (2.6.4)
numpy (1.13.3)
oauthlib (1.0.3)
onboard (1.2.0)
oneconf (0.3.9)
packaging (16.8)
padme (1.1.1)
pandas (0.21.0)
PasteDeploy (1.5.2)
pathos (0.2.1)
pathtools (0.1.2)
pep8 (1.7.0)
pexpect (4.1.0)
pickleshare (0.7.2)
Pillow (3.1.2)
pip (9.0.1)
piston-mini-client (0.7.5)
plainbox (0.25)
pox (0.2.3)
ppft (1.6.4.7.1)
prompt-toolkit (1.0.15)
protobuf (3.3.0)
psutil (4.2.0)
ptpython (0.41)
ptyprocess (0.5.1)
py (1.5.2)
py3-ortools-ubuntu-16.04 (6.3.4431)
pyarrow (0.7.1)
pyasn1 (0.1.9)
pycodestyle (2.3.1)
pycparser (2.18)
pycrypto (2.6.1)
pycups (1.9.73)
pycurl (7.43.0)
pydocstyle (2.0.0)
pyflakes (1.5.0)
Pygments (2.2.0)
pygments-style-cheerfully-dark (0.1)
pygobject (3.20.0)
PyJWT (1.3.0)
pylama (7.4.1)
pylast (1.0.0)
pylint (1.5.5)
pymodbus3 (1.0.0)
PyMySQL (0.7.2)
pyOpenSSL (17.3.0)
pyparsing (2.2.0)
pyramid (1.7)
pyramid-redis (0.1.4)
pyserial (3.4)
pysmbc (1.0.15.5)
pytest (3.2.5)
python-apt (1.1.0b1)
python-dateutil (2.6.1)
python-debian (0.1.27)
python-systemd (231)
pytz (2017.3)
pyxdg (0.25)
PyYAML (3.12)
pyzmq (15.2.0)
QtAwesome (0.4.4)
qtconsole (4.2.1)
QtPy (1.3.1)
quilt (2.7.1, /home/silver/Projects/Work/quilt)
redis (2.10.6)
reportlab (3.3.0)
repoze.lru (0.6)
requests (2.18.4)
responses (0.6.0)
roman (2.0.0)
rope (0.10.3)
rope-py3k (0.9.4.post1)
scipy (0.17.0)
screen-resolution-extra (0.0.0)
sessioninstaller (0.0.0)
setproctitle (1.1.10)
setuptools (38.1.0)
sh (1.12.14)
simplegeneric (0.8.1)
six (1.11.0)
snowballstemmer (1.2.1)
software-center-aptd-plugins (0.0.0)
Sphinx (1.4.1)
sphinx-rtd-theme (0.1.9)
spyder (2.3.8)
SQLAlchemy (1.0.11)
ssh-import-id (5.5)
system-service (0.3)
tables (3.4.2)
tornado (4.3)
tqdm (4.19.4)
traitlets (4.2.1)
translationstring (1.3)
Twisted (17.9.0)
ubuntu-drivers-common (0.0.0)
ufw (0.35)
unattended-upgrades (0.1)
unity-scope-audacious (0.1)
unity-scope-calculator (0.1)
unity-scope-chromiumbookmarks (0.1)
unity-scope-clementine (0.1)
unity-scope-colourlovers (0.1)
unity-scope-devhelp (0.1)
unity-scope-firefoxbookmarks (0.1)
unity-scope-gdrive (0.7)
unity-scope-gmusicbrowser (0.1)
unity-scope-gourmet (0.1)
unity-scope-guayadeque (0.1)
unity-scope-manpages (0.1)
unity-scope-musique (0.1)
unity-scope-openclipart (0.1)
unity-scope-texdoc (0.1)
unity-scope-tomboy (0.1)
unity-scope-virtualbox (0.1)
unity-scope-yelp (0.1)
unity-scope-zotero (0.1)
uritemplate (3.0.0)
urllib3 (1.22)
urwid (1.3.1)
usb-creator (0.3.0)
venusian (1.0)
virtualenv (15.0.1)
watchdog (0.8.3)
wcwidth (0.1.7)
WebOb (1.6.1)
wheel (0.29.0)
wrapt (1.10.8)
xdiagnose (3.8.4.1)
xkit (0.0.0)
xlrd (1.1.0)
XlsxWriter (0.7.3)
xonsh (0.5.12)
zope.component (4.4.0)
zope.deprecation (4.1.2)
zope.event (4.3.0)
zope.interface (4.4.3)

Pytest version:

This is pytest version 3.2.5, imported from /usr/local/lib/python3.5/dist-packages/pytest.py
setuptools registered plugins:
  xonsh-0.5.12 at /usr/local/lib/python3.5/dist-packages/xonsh/pytest_plugin.py
  pylama-7.4.1 at /usr/local/lib/python3.5/dist-packages/pylama/pytest.py

OS Version:
Ubuntu 16.04.3 LTS

@eode eode changed the title "pytest -k " Use of keyword with "-k" option fails if keyword is in an expression Nov 26, 2017
@eode eode changed the title Use of keyword with "-k" option fails if keyword is in an expression Use of python keyword with "-k" option fails if it is in an expression Nov 26, 2017
@nicoddemus nicoddemus added topic: reporting related to terminal output and user-facing messages and errors type: bug problem that needs to be addressed labels Nov 27, 2017
@nicoddemus
Copy link
Member

Thanks @eode!

@eode
Copy link
Author

eode commented Nov 27, 2017

@nicoddemus : No prob, I'll keep an eye here to see if anything else is needed.

@RonnyPfannschmidt
Copy link
Member

the root cause is that we use the python parser to parse/interpret the expressions, as long as that remains, this is pretty much a wontfix

@eode
Copy link
Author

eode commented Dec 19, 2017

Fair enough -- but shouldn't it show something other than:

INTERNALERROR> Traceback (most recent call last):
INTERNALERROR>   File "/home/silver/.virtualenvs/Work/quilt/lib/python3.5/site-packages/_pytest/main.py", line 111, in wrap_session
INTERNALERROR>     session.exitstatus = doit(config, session) or 0
INTERNALERROR>   File "/home/silver/.virtualenvs/Work/quilt/lib/python3.5/site-packages/_pytest/main.py", line 146, in _main
INTERNALERROR>     config.hook.pytest_collection(session=session)
INTERNALERROR>   File "/home/silver/.virtualenvs/Work/quilt/lib/python3.5/site-packages/_pytest/vendored_packages/pluggy.py", line 745, in __call__
INTERNALERROR>     return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
INTERNALERROR>   File "/home/silver/.virtualenvs/Work/quilt/lib/python3.5/site-packages/_pytest/vendored_packages/pluggy.py", line 339, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR>   File "/home/silver/.virtualenvs/Work/quilt/lib/python3.5/site-packages/_pytest/vendored_packages/pluggy.py", line 334, in <lambda>
INTERNALERROR>     _MultiCall(methods, kwargs, hook.spec_opts).execute()
INTERNALERROR>   File "/home/silver/.virtualenvs/Work/quilt/lib/python3.5/site-packages/_pytest/vendored_packages/pluggy.py", line 614, in execute
INTERNALERROR>     res = hook_impl.function(*args)
INTERNALERROR>   File "/home/silver/.virtualenvs/Work/quilt/lib/python3.5/site-packages/_pytest/main.py", line 156, in pytest_collection
INTERNALERROR>     return session.perform_collect()
INTERNALERROR>   File "/home/silver/.virtualenvs/Work/quilt/lib/python3.5/site-packages/_pytest/main.py", line 657, in perform_collect
INTERNALERROR>     config=self.config, items=items)
INTERNALERROR>   File "/home/silver/.virtualenvs/Work/quilt/lib/python3.5/site-packages/_pytest/vendored_packages/pluggy.py", line 745, in __call__
INTERNALERROR>     return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
INTERNALERROR>   File "/home/silver/.virtualenvs/Work/quilt/lib/python3.5/site-packages/_pytest/vendored_packages/pluggy.py", line 339, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR>   File "/home/silver/.virtualenvs/Work/quilt/lib/python3.5/site-packages/_pytest/vendored_packages/pluggy.py", line 334, in <lambda>
INTERNALERROR>     _MultiCall(methods, kwargs, hook.spec_opts).execute()
INTERNALERROR>   File "/home/silver/.virtualenvs/Work/quilt/lib/python3.5/site-packages/_pytest/vendored_packages/pluggy.py", line 614, in execute
INTERNALERROR>     res = hook_impl.function(*args)
INTERNALERROR>   File "/home/silver/.virtualenvs/Work/quilt/lib/python3.5/site-packages/_pytest/mark.py", line 151, in pytest_collection_modifyitems
INTERNALERROR>     if keywordexpr and not matchkeyword(colitem, keywordexpr):
INTERNALERROR>   File "/home/silver/.virtualenvs/Work/quilt/lib/python3.5/site-packages/_pytest/mark.py", line 234, in matchkeyword
INTERNALERROR>     return eval(keywordexpr, {}, mapping)
INTERNALERROR>   File "<string>", line 1
INTERNALERROR>     foo and import
INTERNALERROR>                  ^
INTERNALERROR> SyntaxError: unexpected EOF while parsing

..?

..it should be pretty direct to catch the error or do a quick check for tokens that match keywords, and say "Python keywords not accepted in expressions passed to '-k'."

@RonnyPfannschmidt
Copy link
Member

now thats something we should probably do

and its an easy fix

@RonnyPfannschmidt RonnyPfannschmidt changed the title Use of python keyword with "-k" option fails if it is in an expression show a simple and easy error when keyword expressions trigger a syntax error Dec 19, 2017
@RonnyPfannschmidt RonnyPfannschmidt added good first issue easy issue that is friendly to new contributor type: enhancement new feature or API change, should be merged into features branch type: feature-branch new feature or API change, should be merged into features branch and removed type: bug problem that needs to be addressed labels Dec 19, 2017
@eode
Copy link
Author

eode commented Dec 19, 2017

Sweet! thanks, guys.

@feuillemorte
Copy link
Contributor

Please, review:

#3121

The-Compiler added a commit that referenced this issue Jan 17, 2018
…rror

#2953 show a simple and easy error when keyword expressions trigger a syntax error
raphaelcastaneda pushed a commit to raphaelcastaneda/pytest that referenced this issue Jan 22, 2018
alanbato pushed a commit to alanbato/pytest that referenced this issue Jan 24, 2018
alanbato pushed a commit to alanbato/pytest that referenced this issue Jan 24, 2018
@feuillemorte
Copy link
Contributor

Pull request was merged. Should we close this task?

@nicoddemus
Copy link
Member

Yes, please do the honors @feuillemorte!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue easy issue that is friendly to new contributor topic: reporting related to terminal output and user-facing messages and errors type: enhancement new feature or API change, should be merged into features branch type: feature-branch new feature or API change, should be merged into features branch
Projects
None yet
Development

No branches or pull requests

4 participants