question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

6reactions
arulmrcommented, 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.

4reactions
bluetechcommented, Jun 15, 2020

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

AttributeError: 'Context' object has no attribute 'members' - ...
The first argument passed to a command is always the Context . In this case it's being passed as the guild parameter.
Read more >
Working with Scenes in Python
... AttributeError: 'Context' object has no attribute 'object' location:/usr/share/blender/2.64/scripts/modules/bpy/ops.py:186 Traceback ...
Read more >
'Context' object has no attribute 'view_layer' in Python Script
Autcompleting the bpy.context object does show there's no view_layer property...maybe the docs are outdated? python · scripting · viewlayers.
Read more >
1589393 - Fix CircleCI in Python 3.8
_search_paths(context.pattern, context.path) AttributeError: 'str' object has no attribute 'pattern' Exited with code 1 ...
Read more >
AttributeError: 'Context' object has no attribute 'has_tags'
AttributeError : 'Context' object has no attribute 'has_tags' 2011-05-25 12:32:05,846 Trac[formatter] ERROR: Macro RecentTopics(10) failed: Traceback (most ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found