-
Notifications
You must be signed in to change notification settings - Fork 12
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
Many tests fails with generator raised StopIteration
#200
Comments
Using |
It looks like the proper fix for the issue is this:
|
Would you like to make the PR? |
@mtelka do you have the verbose traces for the error so we can investigate the error cause? |
@abravalheri, here it is:
|
And here is the same test when run without
|
Thank you very much @mtelka. So this is interesting:
Why is Are you sure that you are installing (The test suite is designed to run with the package installed, if that is not possible you might want to skip the The second error is more weird, though:
Why is Finally weirder part is: why this problem only triggers when |
I test using these steps:
AFAIK,
|
Isn't |
In principle no... According to the docs in Thank you for all the information, I will need to have a deeper look at this problem. |
OK, I think I am starting to have some level of understanding now, specially for the weird error:
Apparently Once Now if the hypothesis that |
I am not finding empirical evidence that the hypothesis about > docker run --rm -it python:3.12-bookworm /bin/bash
mkdir -p /tmp/proj && cd /tmp/proj
cat <<EOF > pyproject.toml
[build-system]
requires = ["setuptools>=74.1.2"]
build-backed = "setuptools.build_meta"
EOF
mkdir -p src tests
touch src/proj.py
cat <<EOF > tests/test_paths.py
import sys
def test_paths():
for path in sys.path:
assert "src" not in path
EOF
cat <<EOF > tox.ini
[testenv]
deps = pytest>=8.3.2
commands = pytest {posargs}
EOF
pip install tox
tox # ==> 1 passed in 0.01s
cat <<EOF > pytest.ini
[pytest]
testpaths =
src
tests
EOF
tox # ==> 1 passed in 0.01s
rm pytest.ini
cat <<EOF >> pyproject.toml
[tool.pytest.ini_options]
testpaths = [
"src",
"tests",
]
EOF
tox # ==> 1 passed in 0.01s So now the question is: how the |
Could you please try the same with Python 3.9 too? |
Yes, sorry, it is the same result. pytest always passes. For the sake of completeness: > docker run --rm -it python:3.9-bookworm /bin/bash
mkdir -p /tmp/proj && cd /tmp/proj
cat <<EOF > pyproject.toml
[build-system]
requires = ["setuptools>=74.1.2"]
build-backed = "setuptools.build_meta"
EOF
mkdir -p src tests
touch src/proj.py
cat <<EOF > tests/test_paths.py
import sys
from importlib import metadata
def test_paths():
for path in sys.path:
assert "src" not in path
def test_importlib():
for dist in metadata.Distribution.discover(name="proj"):
assert "src" not in str(dist._path)
EOF
cat <<EOF > tox.ini
[testenv]
deps = pytest>=8.3.2
commands = pytest {posargs}
EOF
pip install tox
tox # ==> 2 passed in 0.01s
cat <<EOF > pytest.ini
[pytest]
testpaths =
src
tests
EOF
tox # ==> 2 passed in 0.01s
rm pytest.ini
cat <<EOF >> pyproject.toml
[tool.pytest.ini_options]
testpaths = [
"src",
"tests",
]
EOF
tox # ==> 2 passed in 0.01s |
Maybe the difference is that you do not have the |
just chiming in: we hit the same issue with the Alpine package for validate-pyproject ( which, in turn, is pulling sources from GitHub tagged releases ) - and the fix from #200 (comment) actually works here |
Sorry guys, I still need to investigate this, but I have been running short of time lately. The behaviour is weird. I need to find out why/when/how the
I don't think so, that folder is automatically created when the project is build by a build-backend. So even when starting from a fresh clone, it will be there... |
So I did this trick: cat <<EOF > conftest.py
import inspect
import sys
class _ImmuatableList(list): pass
def _prevent_modification(target: object, method: str):
fn = getattr(target, method)
def _replacement(self, *args, **kwargs):
curframe = inspect.currentframe()
calframe = inspect.getouterframes(curframe, 2)
print('caller name:', calframe[1][3])
raise NotImplementedError(f"""
Trying to modify sys.path
{method=} {args=} {kwargs=}
{calframe[1].lineno}:{calframe[1].function}:{calframe[1].filename}
{calframe[2].lineno}:{calframe[2].function}:{calframe[2].filename}
{calframe[3].lineno}:{calframe[3].function}:{calframe[3].filename}
""")
setattr(target, method, _replacement)
for _method in (
'__delitem__',
'__iadd__',
'__setitem__',
'append',
'clear',
'extend',
'insert',
'remove',
'reverse',
'pop',
):
_prevent_modification(_ImmuatableList, _method)
sys.path = _ImmuatableList(sys.path)
EOF
tox -e py39 And obtained the following error: conftest.py:13: in _replacement
raise NotImplementedError(f"""
E NotImplementedError:
E Trying to modify sys.path
E method='insert' args=(0, '/home/abravalheri/workspace/validate-pyproject/src') kwargs={}
E 529:import_path:/home/abravalheri/workspace/validate-pyproject/.tox/py39/lib/python3.9/site-packages/_pytest/pathlib.py
E 545:collect:/home/abravalheri/workspace/validate-pyproject/.tox/py39/lib/python3.9/site-packages/_pytest/doctest.py
E 371:<lambda>:/home/abravalheri/workspace/validate-pyproject/.tox/py39/lib/python3.9/site-packages/_pytest/runner.py
------------------------------------------------------------------------------------------------ Captured stdout ------------------------------------------------------------------------------------------------
caller name: import_path
## Repeats the same error for other files I will have to get back to this investigation later (busy days), but I just wanted to document that |
This is probably related to the change in behaviour?
Let me think how we can better change that. Ideally I would not like to exclude the (The recommended import mode for new projects, i.e. "importlib" also seem to have problems pytest-dev/pytest#7652, which I am hitting when working on this). |
I'm seeing 131 tests to fail like this:
I tested both the
0.19
sdist and the latestmain
git branch usingtox -e py39
.I found that when I do this:
touch src/LICENSE src/LICENSE.txt
then all tests pass.The text was updated successfully, but these errors were encountered: