## 错误复现:
git clone git@github.com:TheKevJames/coveralls-python.git
cd coveralls-python
poetry install
poetry run pytest
## 错误内容:
## 完整的打印信息
====================================================== test session starts =======================================================
platform darwin -- Python 3.8.18, pytest-8.2.1, pluggy-1.5.0
rootdir: /Users/mac10.12/github/coveralls-python
configfile: pyproject.toml
collected 59 items / 1 error============================================================= ERRORS =============================================================
_______________________________________________ ERROR collecting tests/cli_test.py _______________________________________________
../../Library/Caches/pypoetry/virtualenvs/coveralls-0IistEsk-py3.8/lib/python3.8/site-packages/_pytest/python.py:492: in importtestmodulemod = import_path(
../../Library/Caches/pypoetry/virtualenvs/coveralls-0IistEsk-py3.8/lib/python3.8/site-packages/_pytest/pathlib.py:591: in import_pathimportlib.import_module(module_name)
/usr/local/opt/python@3.8/Frameworks/Python.framework/Versions/3.8/lib/python3.8/importlib/__init__.py:127: in import_modulereturn _bootstrap._gcd_import(name[level:], package, level)
<frozen importlib._bootstrap>:1014: in _gcd_import???
<frozen importlib._bootstrap>:991: in _find_and_load???
<frozen importlib._bootstrap>:975: in _find_and_load_unlocked???
<frozen importlib._bootstrap>:671: in _load_unlocked???
../../Library/Caches/pypoetry/virtualenvs/coveralls-0IistEsk-py3.8/lib/python3.8/site-packages/_pytest/assertion/rewrite.py:178: in exec_moduleexec(co, module.__dict__)
tests/cli_test.py:8: in <module>import coveralls.cli
coveralls/cli.py:43: in <module>import docopt
E File "/Users/mac10.12/Library/Caches/pypoetry/virtualenvs/coveralls-0IistEsk-py3.8/lib/python3.8/site-packages/docopt.py", line 165
E name = re.findall('(<\S*?>)', source)[0]
E ^
E SyntaxError: invalid escape sequence \S
==================================================== short test summary info =====================================================
ERROR tests/cli_test.py
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
======================================================== 1 error in 1.24s ========================================================
## 原因:
coveralls依赖了docopt模块,而docopt已经有6年没更新了,它并不支持高版本的Python
## 解决:
方案一:使用docopt-ng平替Resolve invalid escape sequence warnings by daugihao · Pull Request #507 · docopt/docopt · GitHub
python -m pip install docopt-ng
方案二:手动修改docopt的源码,在字符串前加上r,如:
- name = re.findall('(<\S*?>)', source)[0]
+ name = re.findall(r'(<\S*?>)', source)[0]