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: module 'posixpath' has no attribute 'sep' #10547

Closed
danschef opened this issue Nov 30, 2022 · 6 comments · Fixed by #10550
Closed

AttributeError: module 'posixpath' has no attribute 'sep' #10547

danschef opened this issue Nov 30, 2022 · 6 comments · Fixed by #10550
Labels
status: help wanted developers would like help from experts on this topic

Comments

@danschef
Copy link
Contributor

Within a Python 3.10 environment and with pytest 7.2.0 installed, it seems like I cannot start the debugger in PyCharm. Instead PyCharm raises the following error:

============================= test session starts ==============================
platform linux -- Python 3.10.8, pytest-7.2.0, pluggy-1.0.0 -- /home/me/mambaforge/envs/myenv/bin/python
cachedir: .pytest_cache
rootdir: /home/me/EnPT
plugins: reporter-html1-0.8.2, cov-4.0.0, reporter-0.5.2
collecting ... 
tests/test_1.py:None (tests/test_1.py)
../../../../mambaforge/envs/myenv/lib/python3.10/site-packages/_pytest/runner.py:339: in from_call
    result: Optional[TResult] = func()
../../../../mambaforge/envs/myenv/lib/python3.10/site-packages/_pytest/runner.py:370: in <lambda>
    call = CallInfo.from_call(lambda: list(collector.collect()), "collect")
../../../../mambaforge/envs/myenv/lib/python3.10/site-packages/_pytest/python.py:532: in collect
    self._inject_setup_module_fixture()
../../../../mambaforge/envs/myenv/lib/python3.10/site-packages/_pytest/python.py:546: in _inject_setup_module_fixture
    self.obj, ("setUpModule", "setup_module")
../../../../mambaforge/envs/myenv/lib/python3.10/site-packages/_pytest/python.py:311: in obj
    self._obj = obj = self._getobj()
../../../../mambaforge/envs/myenv/lib/python3.10/site-packages/_pytest/python.py:529: in _getobj
    return self._importtestmodule()
../../../../mambaforge/envs/myenv/lib/python3.10/site-packages/_pytest/python.py:618: in _importtestmodule
    mod = import_path(self.path, mode=importmode, root=self.config.rootpath)
../../../../mambaforge/envs/myenv/lib/python3.10/site-packages/_pytest/pathlib.py:547: in import_path
    if module_file.endswith(os.path.sep + "__init__.py"):
E   AttributeError: module 'posixpath' has no attribute 'sep'

The environment is running on Ubuntu 20.04 and the error did not appear with Python 3.9.

When replacing os.path.sep with os.sep in .../site-packages/_pytest/pathlib.py, the error goes away.

@nicoddemus
Copy link
Member

The Python docs say it should be available via os.path.sep, so this is strange.

However I think a patch to change this would be harmless too, seems os.sep is the "official" location and os.path.sep is an alias (someone can correct me if this wrong).

@danschef
Copy link
Contributor Author

danschef commented Dec 1, 2022

I just created a pull request to see if this leads to any issues in the CI pipelines: #10550

@Zac-HD
Copy link
Member

Zac-HD commented Dec 2, 2022

My only objection to this is that we're mashing buttons to work around a problem that should be impossible, and that means I have no reason to expect that we're actually fixing it.

If I go look at posixpath.py it's definitely got a sep attribute, so I think your Python install must be subtly but quite nastily broken. Up to you @nicoddemus.

@Zac-HD Zac-HD added the status: help wanted developers would like help from experts on this topic label Dec 2, 2022
@The-Compiler
Copy link
Member

I have a deja-vu: #9791 - judging from the linked issues, it seems to affect (or at least have affected) various different projects.

@Zac-HD
Copy link
Member

Zac-HD commented Dec 2, 2022

Fair enough; let's just merge Daniel's PR (thanks!), which I do expect to fix it here, and hope that's the end of the story!

@danschef
Copy link
Contributor Author

danschef commented Dec 2, 2022

Thanks for merging and pointing me to #9791. That is quite helpful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: help wanted developers would like help from experts on this topic
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants