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.

On startup: AttributeError: 'str' object has no attribute 'pattern'

See original GitHub issue

Pytest fails on startup with the following traceback:

$ pytest
Traceback (most recent call last):
  File "/home/dev/.local/share/virtualenvs/backend/bin/pytest", line 5, in <module>
    from pytest import main
  File "/home/dev/.local/share/virtualenvs/backend/lib/python3.8/site-packages/pytest.py", line 7, in <module>
    from _pytest.assertion import register_assert_rewrite
  File "/home/dev/.local/share/virtualenvs/backend/lib/python3.8/site-packages/_pytest/assertion/__init__.py", line 12, in <module>
    from _pytest.assertion import rewrite
  File "/home/dev/.local/share/virtualenvs/backend/lib/python3.8/site-packages/_pytest/assertion/rewrite.py", line 23, in <module>
    from _pytest.assertion import util
  File "/home/dev/.local/share/virtualenvs/backend/lib/python3.8/site-packages/_pytest/assertion/util.py", line 10, in <module>
    import _pytest._code
  File "/home/dev/.local/share/virtualenvs/backend/lib/python3.8/site-packages/_pytest/_code/__init__.py", line 6, in <module>
    from .code import Code  # noqa
  File "/home/dev/.local/share/virtualenvs/backend/lib/python3.8/site-packages/_pytest/_code/code.py", line 14, in <module>
    import pluggy
  File "/home/dev/.local/share/virtualenvs/backend/lib/python3.8/site-packages/pluggy/__init__.py", line 16, in <module>
    from .manager import PluginManager, PluginValidationError
  File "/home/dev/.local/share/virtualenvs/backend/lib/python3.8/site-packages/pluggy/manager.py", line 6, in <module>
    import importlib_metadata
  File "/home/dev/.local/share/virtualenvs/backend/lib/python3.8/site-packages/importlib_metadata/__init__.py", line 478, in <module>
    __version__ = version(__name__)
  File "/home/dev/.local/share/virtualenvs/backend/lib/python3.8/site-packages/importlib_metadata/__init__.py", line 445, in version
    return distribution(package).version
  File "/home/dev/.local/share/virtualenvs/backend/lib/python3.8/site-packages/importlib_metadata/__init__.py", line 418, in distribution
    return Distribution.from_name(package)
  File "/home/dev/.local/share/virtualenvs/backend/lib/python3.8/site-packages/importlib_metadata/__init__.py", line 179, in from_name
    dists = resolver(name)
  File "<frozen importlib._bootstrap_external>", line 1382, in find_distributions
  File "/home/dev/.local/share/virtualenvs/backend/lib/python3.8/importlib/metadata.py", line 400, in find_distributions
    found = cls._search_paths(context.pattern, context.path)
AttributeError: 'str' object has no attribute 'pattern'

Python version: 3.8.1 Pytest version: 4.5.0 OS: Archlinux 5.4.3

Other packages:

atomicwrites==1.3.0
attrs==19.1.0
backports.functools-lru-cache==1.5
certifi==2019.6.16
chardet==3.0.4
contextlib2==0.5.5
coverage==4.5.4
docopt==0.6.2
future==0.17.1
idna==2.8
importlib-metadata==0.19
jmespath==0.9.4
more-itertools==7.2.0
paho-mqtt==1.3.1
pbr==5.4.2
pluggy==0.12.0
py==1.8.0
pyjwt==1.7.1
pykwalify==1.7.0
pytest-cov==2.7.1
pytest==4.5.0
python-box==3.4.2
python-dateutil==2.8.0
pyyaml==5.1.2
requests==2.22.0
six==1.12.0
stevedore==1.30.1
tavern==0.27.0
urllib3==1.25.3
wcwidth==0.1.7
zipp==0.5.2

Issue Analytics

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

github_iconTop GitHub Comments

5reactions
The-Compilercommented, Jan 16, 2020

Issues which look somewhat related:

So you might want to try upgrading your importlib-metadata and/or pluggy.

1reaction
asottilecommented, Jan 16, 2020

@rubik it doesn’t, in python3.8 we don’t use importlib_metadata we use importlib.metadata

Read more comments on GitHub >

github_iconTop Results From Across the Web

Importing Pytest fails with "AttributeError: 'str' object has no ...
The solution is to update the pluggy dependency (the error happens in version 0.12.0) by running pip install -U pluggy (or pip3 install...
Read more >
Django: AttributeError: 'str' object has no attribute 'resolve'
Here is today's obscure error message and its solution. It's because you forgot to type the word "patterns". Specifically, in some url.py, you...
Read more >
AttributeError: 'str' object has no attribute 'get'
how to solve 'str' object has no attribute 'get' error while trying to execute this code: sns.countplot(x='Survived', data='train').
Read more >
What can I do if I have attribute error: 'str' object has no ... - Quora
Work out what object should have that re attribute and why your code is using a string not the correct object. In my...
Read more >
6.2. re — Regular expression operations - 3.7.9 Documentation
If you're not using a raw string to express the pattern, remember that Python ... 1", "718ak").group(1) AttributeError: 'NoneType' object has no attribute...
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