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

get_resource_reader: IndentationError: unexpected indent #13135

Open
nschloe opened this issue Jan 15, 2025 · 5 comments
Open

get_resource_reader: IndentationError: unexpected indent #13135

nschloe opened this issue Jan 15, 2025 · 5 comments
Labels
status: needs information reporter needs to provide more information; can be closed after 2 or more weeks of inactivity

Comments

@nschloe
Copy link
Contributor

nschloe commented Jan 15, 2025

MWE:

  • Set up venv:

    uv venv
    
    Using CPython 3.13.1 interpreter at: /usr/bin/python
    Creating virtual environment at: .venv
    Activate with: source .venv/bin/activate
    
  • Activate:

    source .venv/bin/activate
    
  • Install pytest:

    uv pip install pytest
    
    Resolved 4 packages in 4ms
    Installed 4 packages in 7ms
     + iniconfig==2.0.0
     + packaging==24.2
     + pluggy==1.5.0
     + pytest==8.3.4
    
  • Run it:

    pytest
    
    Traceback (most recent call last):
      File ".venv/bin/pytest", line 5, in <module>
        from pytest import console_main
      File ".venv/lib/python3.13/site-packages/pytest/__init__.py", line 9, in <module>
        from _pytest.assertion import register_assert_rewrite
      File ".venv/lib/python3.13/site-packages/_pytest/assertion/__init__.py", line 11, in <module>
        from _pytest.assertion import rewrite
      File ".venv/lib/python3.13/site-packages/_pytest/assertion/rewrite.py", line 294
        def get_resource_reader(self, name: str) -> TraversableResources:
    IndentationError: unexpected indent
    

The file in question:

# ...
    def get_data(self, pathname: str | bytes) -> bytes:
        """Optional PEP302 get_data API."""
        with open(pathname, "rb") as f:
            return f.read()

    from importlib.resources.abc import TraversableResources

        def get_resource_reader(self, name: str) -> TraversableResources:
            from importlib.resources.readers import FileReader

            return FileReader(types.SimpleNamespace(path=self._rewritten_names[name]))

# ...
@RonnyPfannschmidt
Copy link
Member

https://github.com/pytest-dev/pytest/blob/517b0066b903e9688beab3377a3bd2439175797f/src/_pytest/assertion/rewrite.py#L276C47-L306C1

it seems your installation is corrupted and something removed conditionals

@RonnyPfannschmidt RonnyPfannschmidt added the status: needs information reporter needs to provide more information; can be closed after 2 or more weeks of inactivity label Jan 15, 2025
@The-Compiler
Copy link
Member

This is wild. I can't reproduce using your steps above, and I agree that something is rewriting pytest's source code here.

Most likely not a pytest issue. Can you show a full terminal session where you do the steps above?

@nschloe
Copy link
Contributor Author

nschloe commented Jan 15, 2025

Can you show a full terminal session where you do the steps above?

@The-Compiler What exactly do you mean by that? Here's a full output:

❯ cd ~/tmp/
❯ mkdir x
❯ cd x
❯ uv venv
Using CPython 3.13.1 interpreter at: /usr/bin/python
Creating virtual environment at: .venv
Activate with: source .venv/bin/activate
❯ source .venv/bin/activate
❯ uv pip install pytest

Resolved 4 packages in 127ms
Installed 4 packages in 11ms
 + iniconfig==2.0.0
 + packaging==24.2
 + pluggy==1.5.0
 + pytest==8.3.4
❯ pytest
Traceback (most recent call last):
  File "/home/nschloe/tmp/x/.venv/bin/pytest", line 5, in <module>
    from pytest import console_main
  File "/home/nschloe/tmp/x/.venv/lib/python3.13/site-packages/pytest/__init__.py", line 9, in <module>
    from _pytest.assertion import register_assert_rewrite
  File "/home/nschloe/tmp/x/.venv/lib/python3.13/site-packages/_pytest/assertion/__init__.py", line 11, in <module>
    from _pytest.assertion import rewrite
  File "/home/nschloe/tmp/x/.venv/lib/python3.13/site-packages/_pytest/assertion/rewrite.py", line 294
    def get_resource_reader(self, name: str) -> TraversableResources:
IndentationError: unexpected indent
~/tmp/x ❯  

@The-Compiler
Copy link
Member

Yep, that. Basically I'm looking at any clues to see what could be happening, and a full 1:1 terminal session can help with that. However, I'm still at a loss. Evidently something is tampering with pytest's source code on your system somehow.

Could you rerun with -v added to both uv steps and share the debug logs? Also, can you reproduce if you use python3 -m venv .venv and pip, i.e. cutting uv out of the picture?

@The-Compiler
Copy link
Member

The-Compiler commented Jan 15, 2025

Oh, and could you also please upload your entire:

  • .venv/lib/python3.13/site-packages/_pytest/
  • .venv/lib/python3.13/site-packages/pytest/
  • .venv/lib/python3.13/site-packages/pytest-8.3.4.dist-info/

somewhere? Maybe there is more clues in there on what's going on, when looking at the difference to what's actually uploaded to PyPI by pytest.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: needs information reporter needs to provide more information; can be closed after 2 or more weeks of inactivity
Projects
None yet
Development

No branches or pull requests

3 participants