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

bad delayed error on invalid keyword expression #3573

Closed
hroncok opened this issue Jun 12, 2018 · 5 comments · Fixed by #7122
Closed

bad delayed error on invalid keyword expression #3573

hroncok opened this issue Jun 12, 2018 · 5 comments · Fixed by #7122
Labels
topic: collection related to the collection phase topic: reporting related to terminal output and user-facing messages and errors

Comments

@hroncok
Copy link
Member

hroncok commented Jun 12, 2018

I have trouble to replicate this outside of Fedora build system, because bodhi has non-pip-installable dependencies.

However in Fedora build system with 3.7.0b5 installed and couple of dependencies:

python3-alembic.noarch 0.9.7-4.fc29 
python3-arrow.noarch 0.10.0-5.fc29
python3-asn1crypto.noarch 0.24.0-1.fc29
python3-atomicwrites.noarch 1.1.5-8.fc29
python3-attrs.noarch 17.4.0-4.fc29
python3-babel.noarch 2.5.1-2.fc29
python3-beanbag.noarch 1.9.2-9.fc29 
python3-beautifulsoup4.noarch 4.6.0-6.fc29
python3-bleach.noarch 2.1.3-1.fc29
python3-bugzilla.noarch 2.1.0-6.fc29
python3-cairo.x86_64 1.16.3-1.fc29
python3-cffi.x86_64 1.11.5-2.fc29
python3-click.noarch 6.7-7.fc29
python3-colander.noarch 1.4-3.fc29
python3-cornice.noarch 3.1.0-1.fc29 
python3-cornice-sphinx.noarch 1:0.3-4.fc29
python3-coverage.x86_64 4.5.1-1.fc29
python3-createrepo_c.x86_64 0.10.0-20.fc29
python3-cryptography.x86_64 2.2.1-1.fc29
python3-daemon.noarch 2.1.2-8.fc29
python3-dateutil.noarch 1:2.7.0-1.fc29 
python3-decorator.noarch 4.2.1-1.fc29
python3-defusedxml.noarch 0.5.0-4.fc29 
python3-devel.x86_64 3.7.0-0.19.b5.fc29
python3-dnf.noarch 2.7.5-17.fc29 
python3-dnf-plugins-core.noarch 2.1.5-4.fc29 
python3-docutils.noarch 0.14-3.fc29 
python3-dogpile-cache.noarch 0.6.5-1.fc29 
python3-editor.noarch 1.0.3-7.fc29
python3-fedmsg.noarch 1.1.1-1.fc29
python3-fedora.noarch 0.10.0-3.fc29 
python3-feedgen.noarch 0.7.0-1.fc29 
python3-flake8.noarch 3.5.0-4.fc29
python3-funcsigs.noarch 1.0.2-9.fc29
python3-gobject-base.x86_64 3.28.3-1.fc29 
python3-gobject.x86_64 3.28.3-1.fc29
python3-gpg.x86_64 1.11.1-1.fc29 
python3-hawkey.x86_64 0.11.1-5.fc29 
python3-html5lib.noarch 1:0.999999999-6.fc29 
python3-hupper.noarch 0.4.2-4.fc29
python3-chameleon.noarch 3.2-3.fc29 
python3-chardet.noarch 3.0.4-5.fc29 
python3-idna.noarch 2.5-4.fc29
python3-imagesize.noarch 1.0.0-1.fc29
python3-iniparse.noarch 0.4-30.fc29 
python3-iso8601.noarch 0.1.11-9.fc29
python3-jinja2.noarch 2.10-3.fc29
python3-jsonschema.noarch 2.6.0-4.fc29 
python3-kerberos.x86_64 1.3.0-1.fc29
python3-kickstart.noarch 3.14-2.fc29
python3-kitchen.noarch 1.2.5-4.fc29 
python3-kobo.noarch 0.7.0-7.fc29 
python3-kobo-rpmlib.noarch 0.7.0-7.fc29
python3-koji-cli-plugins.noarch 1.15.1-1.fc29
python3-koji.noarch 1.15.1-1.fc29
python3-libcomps.x86_64 0.1.8-12.fc29
python3-librepo.x86_64 1.8.1-7.fc29 
python3-libs.x86_64 3.7.0-0.19.b5.fc29 
python3-lockfile.noarch 1:0.11.0-10.fc29
python3-lxml.x86_64 4.2.1-1.fc29 
python3-magic.noarch 5.33-6.fc29 
python3-mako.noarch 1.0.6-9.fc29 
python3-markdown.noarch 2.6.11-2.fc29
python3-markupsafe.x86_64 0.23-17.fc29 
python3-mccabe.noarch 0.6.1-7.fc29
python3-mock.noarch 2.0.0-8.fc29 
python3-moksha-common.noarch 1.2.5-6.fc29 
python3-moksha-hub.noarch 1.5.9-1.fc29 
python3-more-itertools.noarch 4.1.0-2.fc29
python3-multilib.noarch 1.2-4.fc29
python3-munch.noarch 2.2.0-4.fc29
python3-olefile.noarch 0.45.1-1.fc29
python3-openidc-client.noarch 0.6.0-1.20180605gitcd8d91c.fc29
python3-openid-cla.noarch 1.2-8.fc29
python3-openid.noarch 3.1.0-1.fc29
python3-openid-teams.noarch 1.1-11.fc29
python3-ordered-set.noarch 2.0.2-4.fc29
python3-packaging.noarch 16.8-8.fc29
python3-paste-deploy.noarch 1.5.2-14.fc29 
python3-paste.noarch 2.0.3-6.fc29
python3-pbr.noarch 3.1.1-7.fc29
python3-pdc-client.noarch 1.8.0-6.fc29 
python3-pillow.x86_64 5.1.1-1.fc29
python3-pip.noarch 9.0.3-2.fc29
python3-plaster.noarch 0.5-3.fc29
python3-plaster-pastedeploy.noarch 0.4.2-2.fc29 
python3-pluggy.noarch 0.6.0-2.fc29
python3-ply.noarch 3.9-6.fc29 
python3-productmd.noarch 1.14-1.fc29
python3-psutil.x86_64 5.4.3-4.fc29
python3-pungi.noarch 4.1.25-4.fc29
python3-pyasn1-modules.noarch 0.3.7-3.fc29
python3-pyasn1.noarch 0.3.7-3.fc29
python3-pycodestyle.noarch 2.4.0-1.fc29
python3-pycparser.noarch 2.14-14.fc29
python3-pycurl.x86_64 7.43.0.2-1.fc29
python3-pyflakes.noarch 2.0.0-1.fc29
python3-pygments.noarch 2.2.0-11.fc29
python3-pylibravatar.noarch 1.6-15.fc29
python3-py.noarch 1.5.3-1.fc29
python3-pyOpenSSL.noarch 17.3.0-4.fc29 
python3-pyparsing.noarch 2.2.0-1.fc29
python3-pyramid-fas-openid.noarch 0.3.9-3.fc29
python3-pyramid-mako.noarch 1.0.2-6.fc29
python3-pyramid.noarch 1.9.1-4.fc29 
python3-pyramid-tm.noarch 2.2-3.fc29
python3-pyserial.noarch 3.1.1-7.fc29
python3-pysocks.noarch 1.6.8-2.fc29 
python3-pytest-cov.noarch 2.5.1-4.fc29 
python3-pytest.noarch 3.6.1-1.fc29
python3-pytz.noarch 2017.2-8.fc29
python3-PyYAML.x86_64 3.12-10.fc29
python3-py3dns.noarch 3.1.1-6.fc29
python3-repoze-lru.noarch 0.4-18.fc29
python3-requests-kerberos.noarch 0.12.0-2.fc29
python3-requests.noarch 2.18.4-6.fc29
python3-rpm-generators.noarch 5-1.fc28 
python3-rpm-macros.noarch 3-29.fc29 
python3-rpm.x86_64 4.14.1-10.fc29
python3-service-identity.noarch 16.0.0-9.fc29
python3-setuptools.noarch 39.2.0-1.fc29
python3-simplejson.x86_64 3.10.0-7.fc29
python3-simplemediawiki.noarch 1.2.0-0.13.b2.fc29
python3-six.noarch 1.11.0-3.fc29 
python3-smartcols.x86_64 0.3.0-2.fc29
python3-snowballstemmer.noarch 1.2.1-5.fc29
python3-sphinxcontrib-websupport.noarch 1.0.1-8.20180316git.fc29
python3-sphinx.noarch 1:1.7.2-3.fc29
python3-sphinx_rtd_theme.noarch 0.3.1-1.fc29 
python3-sphinx-theme-alabaster.noarch 0.7.9-6.fc29 
python3-sqlalchemy.x86_64 1.2.7-1.fc29 
python3-stomper.noarch 0.4.1-5.fc29 
python3-tempita.noarch 0.5.1-19.fc29
python3-transaction.noarch 2.2.0-1.fc29
python3-translationstring.noarch 1.3-6.fc29
python3-twisted.x86_64 16.4.1-10.fc29
python3-txws.noarch 0.9.1-11.fc29
python3-txzmq.noarch 0.8.0-5.fc29
python3-urllib3.noarch 1.23-1.fc29
python3-venusian.noarch 1.0-0.20.a7.fc29
python3-virtualenv.noarch 16.0.0-1.fc29
python3-waitress.noarch 1.1.0-2.fc29
python3-webencodings.noarch 0.5.1-4.fc29
python3-webob.noarch 1.8.1-1.fc29
python3-webtest.noarch 2.0.29-5.fc29 
python3-whoosh.noarch 2.7.4-9.fc29
python3-zmq.x86_64 17.0.0-1.fc29 
python3-zope-component.noarch 4.3.0-5.fc29
python3-zope-configuration.noarch 4.0.3-12.fc29 
python3-zope-deprecation.noarch 4.3.0-2.fc29 
python3-zope-event.noarch 4.2.0-8.fc29 
python3-zope-interface.x86_64 4.4.3-1.fc29
python3-zope-i18nmessageid.x86_64 4.0.3-11.fc29 
python3-zope-schema.noarch 4.4.2-10.fc29 

I hit a problem when using -k:

+ .test-virtualenv-3/bin/python3 /usr/bin/py.test-3 -k 'not TestExceptionFilter.test_exception and not Test_SendMail.test_recipients_refused'
============================= test session starts ==============================
platform linux -- Python 3.7.0b5, pytest-3.6.1, py-1.5.3, pluggy-0.6.0
rootdir: /builddir/build/BUILD/bodhi-3.8.0, inifile: setup.cfg
plugins: cov-2.5.1
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR>   File "/usr/lib/python3.7/site-packages/_pytest/main.py", line 178, in wrap_session
INTERNALERROR>     session.exitstatus = doit(config, session) or 0
INTERNALERROR>   File "/usr/lib/python3.7/site-packages/_pytest/main.py", line 214, in _main
INTERNALERROR>     config.hook.pytest_collection(session=session)
INTERNALERROR>   File "/usr/lib/python3.7/site-packages/pluggy/__init__.py", line 617, in __call__
INTERNALERROR>     return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
INTERNALERROR>   File "/usr/lib/python3.7/site-packages/pluggy/__init__.py", line 222, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR>   File "/usr/lib/python3.7/site-packages/pluggy/__init__.py", line 216, in <lambda>
INTERNALERROR>     firstresult=hook.spec_opts.get('firstresult'),
INTERNALERROR>   File "/usr/lib/python3.7/site-packages/pluggy/callers.py", line 201, in _multicall
INTERNALERROR>     return outcome.get_result()
INTERNALERROR>   File "/usr/lib/python3.7/site-packages/pluggy/callers.py", line 76, in get_result
INTERNALERROR>     raise ex[1].with_traceback(ex[2])
INTERNALERROR>   File "/usr/lib/python3.7/site-packages/pluggy/callers.py", line 180, in _multicall
INTERNALERROR>     res = hook_impl.function(*args)
INTERNALERROR>   File "/usr/lib/python3.7/site-packages/_pytest/main.py", line 224, in pytest_collection
INTERNALERROR>     return session.perform_collect()
INTERNALERROR>   File "/usr/lib/python3.7/site-packages/_pytest/main.py", line 429, in perform_collect
INTERNALERROR>     session=self, config=self.config, items=items
INTERNALERROR>   File "/usr/lib/python3.7/site-packages/pluggy/__init__.py", line 617, in __call__
INTERNALERROR>     return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
INTERNALERROR>   File "/usr/lib/python3.7/site-packages/pluggy/__init__.py", line 222, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR>   File "/usr/lib/python3.7/site-packages/pluggy/__init__.py", line 216, in <lambda>
INTERNALERROR>     firstresult=hook.spec_opts.get('firstresult'),
INTERNALERROR>   File "/usr/lib/python3.7/site-packages/pluggy/callers.py", line 201, in _multicall
INTERNALERROR>     return outcome.get_result()
INTERNALERROR>   File "/usr/lib/python3.7/site-packages/pluggy/callers.py", line 76, in get_result
INTERNALERROR>     raise ex[1].with_traceback(ex[2])
INTERNALERROR>   File "/usr/lib/python3.7/site-packages/pluggy/callers.py", line 180, in _multicall
INTERNALERROR>     res = hook_impl.function(*args)
INTERNALERROR>   File "/usr/lib/python3.7/site-packages/_pytest/mark/__init__.py", line 155, in pytest_collection_modifyitems
INTERNALERROR>     deselect_by_keyword(items, config)
INTERNALERROR>   File "/usr/lib/python3.7/site-packages/_pytest/mark/__init__.py", line 124, in deselect_by_keyword
INTERNALERROR>     if keywordexpr and not matchkeyword(colitem, keywordexpr):
INTERNALERROR>   File "/usr/lib/python3.7/site-packages/_pytest/mark/legacy.py", line 95, in matchkeyword
INTERNALERROR>     return eval(keywordexpr, {}, mapping)
INTERNALERROR>   File "<string>", line 1, in <module>
INTERNALERROR> AttributeError: 'bool' object has no attribute 'test_exception'
========================== 8 warnings in 6.25 seconds ==========================

That's Python 3.7.0b5, pytest-3.6.1, py-1.5.3, pluggy-0.6.0.

Does this sound familiar? Google is not helpful.

@hroncok hroncok added the topic: collection related to the collection phase label Jun 12, 2018
@pytestbot
Copy link
Contributor

GitMate.io thinks possibly related issues are #1133 (InternalError: AttributeError: 'str' object has no attribute 'relto'), #1184 (Internal Error: AttributeError: 'str' object has no attribute 'relate'), #1365 (py.test occurred error in selenium "AttributeError: 'NoneType' object has no attribute 'fork_exec'"), #1805 (Fixture that calls getattr() on request.function throws an AttributeError: 'function' object has no attribute), and #1310 (AttributeError: '_HookCaller' object has no attribute 'spec_opts').

@RonnyPfannschmidt
Copy link
Member

keword expressions don't suport nested object access

there ought to be a better error, right now all we do is run the code and it has to break, because TestExceptionFilter returns True or False, then the rest of the expression is attribute access on that boolean

@RonnyPfannschmidt RonnyPfannschmidt added the type: question general question, might be closed after 2 weeks of inactivity label Jun 12, 2018
@hroncok
Copy link
Member Author

hroncok commented Jun 12, 2018

oh! My bad. should we keep this open for a better error message?

@RonnyPfannschmidt
Copy link
Member

yes, let me shift thins around

@RonnyPfannschmidt RonnyPfannschmidt changed the title INTERNALERROR> AttributeError: 'bool' object has no attribute 'test_exception' bad delayed error on invalid keyword expression Jun 12, 2018
@RonnyPfannschmidt RonnyPfannschmidt added topic: reporting related to terminal output and user-facing messages and errors and removed type: question general question, might be closed after 2 weeks of inactivity labels Jun 12, 2018
@RonnyPfannschmidt
Copy link
Member

RonnyPfannschmidt commented Jun 12, 2018

the solution would be to either introduce a chainable keyword boolean

so that foo.bar would be equivalent to (foo and bar)

not TestExceptionFilter.test_exception and not Test_SendMail.test_recipients_refused currently needs to be spelled as

not (TestExceptionFilter and test_exception) and not (Test_SendMail and test_recipients_refused) it should be noted that this actually filters for contained strings and not full matches

bluetech added a commit to bluetech/pytest that referenced this issue Apr 25, 2020
Previously, the expressions given to the `-m` and `-k` options were
evaluated with `eval`. This causes a few issues:

- Python keywords cannot be used.

- Constants like numbers, None, True, False are not handled correctly.

- Various syntax like numeric operators and `X if Y else Z` is supported
  unintentionally.

- `eval()` is somewhat dangerous for arbitrary input.

- Can fail in many ways so requires `except Exception`.

The format we want to support is quite simple, so change to a custom
parser. This fixes the issues above, and gives us full control of the
format, so can be documented comprehensively and even be extended in the
future if we wish.

Fixes pytest-dev#1141.
Fixes pytest-dev#3573.
Fixes pytest-dev#5881.
Fixes pytest-dev#6822.
Fixes pytest-dev#7112.
bluetech added a commit to bluetech/pytest that referenced this issue Apr 25, 2020
Previously, the expressions given to the `-m` and `-k` options were
evaluated with `eval`. This causes a few issues:

- Python keywords cannot be used.

- Constants like numbers, None, True, False are not handled correctly.

- Various syntax like numeric operators and `X if Y else Z` is supported
  unintentionally.

- `eval()` is somewhat dangerous for arbitrary input.

- Can fail in many ways so requires `except Exception`.

The format we want to support is quite simple, so change to a custom
parser. This fixes the issues above, and gives us full control of the
format, so can be documented comprehensively and even be extended in the
future if we wish.

Fixes pytest-dev#1141.
Fixes pytest-dev#3573.
Fixes pytest-dev#5881.
Fixes pytest-dev#6822.
Fixes pytest-dev#7112.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: collection related to the collection phase topic: reporting related to terminal output and user-facing messages and errors
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants