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

AttributeError: 'Context' object has no attribute 'pattern' #7371

Closed
arulmr opened this issue Jun 14, 2020 · 6 comments
Closed

AttributeError: 'Context' object has no attribute 'pattern' #7371

arulmr opened this issue Jun 14, 2020 · 6 comments

Comments

@arulmr
Copy link

arulmr commented Jun 14, 2020

I'm getting the following error when I run pytest:

Traceback (most recent call last):
  File "/home/arul/venvs/benir/bin/pytest", line 8, in <module>
    sys.exit(main())
  File "/home/arul/venvs/benir/lib/python3.8/site-packages/_pytest/config/__init__.py", line 105, in main
    config = _prepareconfig(args, plugins)
  File "/home/arul/venvs/benir/lib/python3.8/site-packages/_pytest/config/__init__.py", line 257, in _prepareconfig
    return pluginmanager.hook.pytest_cmdline_parse(
  File "/home/arul/venvs/benir/lib/python3.8/site-packages/pluggy/hooks.py", line 286, in __call__
    return self._hookexec(self, self.get_hookimpls(), kwargs)
  File "/home/arul/venvs/benir/lib/python3.8/site-packages/pluggy/manager.py", line 93, in _hookexec
    return self._inner_hookexec(hook, methods, kwargs)
  File "/home/arul/venvs/benir/lib/python3.8/site-packages/pluggy/manager.py", line 84, in <lambda>
    self._inner_hookexec = lambda hook, methods, kwargs: hook.multicall(
  File "/home/arul/venvs/benir/lib/python3.8/site-packages/pluggy/callers.py", line 203, in _multicall
    gen.send(outcome)
  File "/home/arul/venvs/benir/lib/python3.8/site-packages/_pytest/helpconfig.py", line 90, in pytest_cmdline_parse
    config = outcome.get_result()
  File "/home/arul/venvs/benir/lib/python3.8/site-packages/pluggy/callers.py", line 80, in get_result
    raise ex[1].with_traceback(ex[2])
  File "/home/arul/venvs/benir/lib/python3.8/site-packages/pluggy/callers.py", line 187, in _multicall
    res = hook_impl.function(*args)
  File "/home/arul/venvs/benir/lib/python3.8/site-packages/_pytest/config/__init__.py", line 836, in pytest_cmdline_parse
    self.parse(args)
  File "/home/arul/venvs/benir/lib/python3.8/site-packages/_pytest/config/__init__.py", line 1044, in parse
    self._preparse(args, addopts=addopts)
  File "/home/arul/venvs/benir/lib/python3.8/site-packages/_pytest/config/__init__.py", line 992, in _preparse
    self.pluginmanager.load_setuptools_entrypoints("pytest11")
  File "/home/arul/venvs/benir/lib/python3.8/site-packages/pluggy/manager.py", line 289, in load_setuptools_entrypoints
    for dist in importlib_metadata.distributions():
  File "/usr/lib/python3.8/importlib/metadata.py", line 194, in <genexpr>
    resolver(context)
  File "/home/arul/venvs/benir/lib/python3.8/site-packages/importlib_metadata/__init__.py", line 417, in find_distributions
    found = self._search_paths(context.pattern, context.path)
AttributeError: 'Context' object has no attribute 'pattern'

Packages:

Package               Version
--------------------- ---------
amqp                  2.5.1
appdirs               1.4.3
asgiref               3.2.7
attrs                 19.3.0
backcall              0.1.0
beautifulsoup4        4.8.1
billiard              3.6.1.0
bleach                3.1.0
boto3                 1.9.253
botocore              1.12.253
CacheControl          0.12.6
cairocffi             1.1.0
CairoSVG              2.4.2
celery                4.3.0
certifi               2019.9.11
cffi                  1.13.1
chardet               3.0.4
colorama              0.4.3
contextlib2           0.6.0
coverage              4.5.4
cssselect2            0.2.2
decorator             4.4.0
defusedxml            0.6.0
distlib               0.3.0
distro                1.4.0
Django                2.2.6
django-admin-tools    0.8.1
django-appconf        1.0.3
django-autoslug       1.9.6
django-compressor     2.3
django-debug-toolbar  2.0
django-extensions     2.2.5
django-mathfilters    0.4.0
django-statsd-mozilla 0.4.0
django-storages       1.7.2
docopt                0.6.2
docutils              0.15.2
elastic-apm           5.2.2
elasticsearch         7.1.0
entrypoints           0.3
html5lib              1.0.1
idna                  2.8
importlib-metadata    0.23
instamojo-wrapper     1.2.0
ipaddr                2.2.0
ipdb                  0.12.2
ipykernel             5.1.3
ipython               7.8.0
ipython-genutils      0.2.0
ipywidgets            7.5.1
jedi                  0.15.1
Jinja2                2.10.3
jmespath              0.9.4
jsonschema            3.1.1
jupyter-client        5.3.4
jupyter-core          4.6.0
kombu                 4.6.5
limits                1.3
lockfile              0.12.2
MarkupSafe            1.1.1
mistune               0.8.4
more-itertools        8.4.0
msgpack               0.6.2
nbconvert             5.6.0
nbformat              4.4.0
notebook              6.0.1
num2words             0.5.10
packaging             20.3
pandocfilters         1.4.2
parso                 0.5.1
pdfrw                 0.4
pep517                0.8.2
pexpect               4.7.0
pickleshare           0.7.5
Pillow                6.2.1
pip                   20.1.1
pip-review            1.0
pipdeptree            0.13.2
pluggy                0.13.1
progress              1.5
prometheus-client     0.7.1
prompt-toolkit        2.0.10
psutil                5.6.3
psycopg2-binary       2.8.4
ptyprocess            0.6.0
py                    1.8.1
pycparser             2.19
PyExcelerate          0.8.0
Pygments              2.4.2
pylogbeat             1.0.2
pyparsing             2.4.7
Pyphen                0.9.5
pyrsistent            0.15.4
pytest                5.4.3
pytest-cov            2.8.1
pytest-django         3.6.0
python-dateutil       2.8.0
python-logstash       0.4.6
python-logstash-async 1.5.1
pytoml                0.1.21
pytz                  2019.3
pyzmq                 18.1.0
rcssmin               1.0.6
redis                 3.3.11
requests              2.22.0
responses             0.10.6
retrying              1.3.3
rjsmin                1.1.0
s3transfer            0.2.1
Send2Trash            1.5.0
setuptools            46.1.3
simplegeneric         0.8.1
six                   1.14.0
soupsieve             2.0
sqlparse              0.3.0
statsd                3.3.0
terminado             0.8.2
testpath              0.4.2
tinycss2              1.0.2
toml                  0.10.1
tornado               6.0.3
traitlets             4.3.3
typing                3.7.4.1
urllib3               1.22
vine                  1.3.0
wcwidth               0.1.9
WeasyPrint            50
webencodings          0.5.1
Werkzeug              0.16.0
wheel                 0.34.2
widgetsnbextension    3.5.1
xlrd                  1.2.0
XlsxWriter            1.2.2
xlwt                  1.3.0
zipp                  0.6.0

Versions:

OS: Ubuntu 20.04 (WSL2)
Python: 3.8.2
Pytest: 5.4.3

  1. The tests run fine on Ubuntu 19.10(WSL2) with Python 3.7.5.
  2. I'm able to run tests for other applications in the same OS where I face the issue for this application.
@Zac-HD
Copy link
Member

Zac-HD commented Jun 15, 2020

Hmm. It looks like you have importlib-metadata installed under Python 3.8, when it should be present in the standard library anyway. Does pip uninstall importlib-metadata help?

@arulmr
Copy link
Author

arulmr commented Jun 15, 2020

@Zac-HD Uninstalling importlib-metadata caused package missing error. But upgrading it to the newer version resolved my issue. I've upgraded importlib-metadata from v0.23 to v1.6.1. I'm able to run the tests now. Thank you so much for your help.

@arulmr arulmr closed this as completed Jun 15, 2020
@RonnyPfannschmidt
Copy link
Member

@

@RonnyPfannschmidt
Copy link
Member

reopening as a downstream issue with pluggy

@bluetech
Copy link
Member

Both pluggy and pytest import importlib_metadata like this:

if sys.version_info >= (3, 8):
    from importlib import metadata as importlib_metadata
else:
    import importlib_metadata

and indeed the stacktrace goes through the stdlib importlib.metadata initially:

  File "/home/arul/venvs/benir/lib/python3.8/site-packages/pluggy/manager.py", line 289, in load_setuptools_entrypoints
    for dist in importlib_metadata.distributions():
  File "/usr/lib/python3.8/importlib/metadata.py", line 194, in <genexpr>
    resolver(context)
  File "/home/arul/venvs/benir/lib/python3.8/site-packages/importlib_metadata/__init__.py", line 417, in find_distributions
    found = self._search_paths(context.pattern, context.path)

What resolver(context) does is go through sys.meta_path, to which importlib_metadata 0.23 inserts itself on import. Looks like it doesn't do that anymore since version 1.0.

So I'm closing this due to:

  • Some package in the list imports importlib_metatdata instead of importlib.metadata on Python 3.8, but it's not pytest or pluggy. @arulmr you might be able to find the problematic package by grepping for import importlib_metadata in your venv directory or such, and checking if it first tries to import importlib.metadata or not.

  • The version of importlib_metadata used doesn't handle it well, but fixed in newer versions.

@RonnyPfannschmidt
Copy link
Member

lovely, thanks

diurnalist pushed a commit to ChameleonCloud/doni that referenced this issue Dec 3, 2021
See pytest-dev/pytest#7371 (comment)
for more context on this issue.
diurnalist pushed a commit to ChameleonCloud/doni that referenced this issue Dec 3, 2021
See pytest-dev/pytest#7371 (comment)
for more context on this issue.
mmore500 added a commit to mmore500/nanto that referenced this issue Mar 4, 2022
ehudkr added a commit to BiomedSciAI/causallib that referenced this issue Apr 6, 2022
Fix a bug when calling `OutcomeEvaluator` with custom metrics due to
positional arguments misalignment.

Fix an issue with Travis failing to install in a Python 3.7 build.
* https://app.travis-ci.com/github/IBM/causallib/jobs/565683172
* pytest-dev/pytest#7371 (comment)
* tobinus/python-podgen#124


Co-authored-by: ehudkr <ehudkaravani@gmail.com>
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

No branches or pull requests

4 participants