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

test_pyexpat: test_exception() fails on Ubuntu and macOS jobs on GitHub Actions #109230

Closed
vstinner opened this issue Sep 10, 2023 · 4 comments
Closed
Labels
tests Tests in the Lib/test dir type-bug An unexpected behavior, bug, or error

Comments

@vstinner
Copy link
Member

vstinner commented Sep 10, 2023

FAIL: test_exception (test.test_pyexpat.HandlerExceptionTest.test_exception)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/runner/work/cpython/cpython-ro-srcdir/Lib/test/test_pyexpat.py", line 452, in test_exception
    parser.Parse(b"<a><b><c/></b></a>", True)
  File "../cpython-ro-srcdir/Modules/pyexpat.c", line 421, in StartElement
  File "/home/runner/work/cpython/cpython-ro-srcdir/Lib/test/test_pyexpat.py", line 442, in StartElementHandler
    raise RuntimeError(name)
RuntimeError: a

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/runner/work/cpython/cpython-ro-srcdir/Lib/test/test_pyexpat.py", line 472, in test_exception
    self.assertIn('call_with_frame("StartElement"', entries[1][3])
AssertionError: 'call_with_frame("StartElement"' not found in ''

Comparison of Ubuntu logs:

Linked PRs

@vstinner vstinner changed the title test_pyexpat: test_pyexpat: test_exception() fails on Ubuntu and macOS jobs on GitHub Actions Sep 10, 2023
@vstinner vstinner added type-bug An unexpected behavior, bug, or error tests Tests in the Lib/test dir labels Sep 10, 2023
@vstinner
Copy link
Member Author

Oh wait. Maybe it's a real bug in my PR #109229.

@vstinner
Copy link
Member Author

Oh. This test depends on the current working directory!

If it's run from the source directory, it pass.

$ pwd
/home/vstinner/python/main

$ ls Modules/pyexpat.c
Modules/pyexpat.c

vstinner@mona$ ./python -m test -v test_pyexpat -m test_exception  -q
(...)
Result: SUCCESS

If it's run from a different directory, it fails!

$ cd ..

$ pwd
/home/vstinner/python

$ ls Modules/pyexpat.c
ls: cannot access 'Modules/pyexpat.c': No such file or directory

$ main/python -m test -v test_pyexpat -m test_exception  -q
(...)
test test_pyexpat failed -- Traceback (most recent call last):
  File "/home/vstinner/python/main/Lib/test/test_pyexpat.py", line 452, in test_exception
    parser.Parse(b"<a><b><c/></b></a>", True)
  File "./Modules/pyexpat.c", line 421, in StartElement
  File "/home/vstinner/python/main/Lib/test/test_pyexpat.py", line 442, in StartElementHandler
    raise RuntimeError(name)
RuntimeError: a

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/vstinner/python/main/Lib/test/test_pyexpat.py", line 472, in test_exception
    self.assertIn('call_with_frame("StartElement"', entries[1][3])
AssertionError: 'call_with_frame("StartElement"' not found in ''

(...)
Result: FAILURE

@vstinner
Copy link
Member Author

The test checks that the traceback module is able to read a line of the Python C code in Modules/pyexpat.c. The test was added by commit 0ddbf47 in issue #66652 which added _PyTraceback_Add().

Quickly, the test was skipped if sysconfig.is_python_build() is false: commit 2b3b95b.

In 2022, the test was skipped on WASM and Win32 ARM: commit 96b344c. These two platforms build Python with cross-compilation: the target Python doesn't have access to Python C source code. A minor follow-up also skipped the test on WASI: commit 9b50585.

IMO the condition to decide to skip the test or not is weak. And the test should not depend on which directory tests are run.

vstinner added a commit to vstinner/cpython that referenced this issue Sep 10, 2023
Fix test_pyexpat.test_exception(): it can now be run from a directory
different than Python source code directory. Before, the test failed
in this case. Moreover, skip the test if Modules/pyexpat.c doesn't
exist and other Python implementations other than CPython.
vstinner added a commit to vstinner/cpython that referenced this issue Sep 10, 2023
Fix test_pyexpat.test_exception(): it can now be run from a directory
different than Python source code directory. Before, the test failed
in this case.

Skip the test if Modules/pyexpat.c source is not available. Skip also
the test on Python implementations other than CPython.
@vstinner
Copy link
Member Author

Oh wait. Maybe it's a real bug in my PR #109229.

My PR makes the issue easier to reproduce since running the Python test suite with -j1 option changes the current working directory and so trigger the bug.

vstinner added a commit to vstinner/cpython that referenced this issue Sep 10, 2023
Fix test_pyexpat.test_exception(): it can now be run from a directory
different than Python source code directory. Before, the test failed
in this case.

Skip the test if Modules/pyexpat.c source is not available. Skip also
the test on Python implementations other than CPython.
vstinner added a commit that referenced this issue Sep 10, 2023
…109233)

Fix test_pyexpat.test_exception(): it can now be run from a directory
different than Python source code directory. Before, the test failed
in this case.

Skip the test if Modules/pyexpat.c source is not available. Skip also
the test on Python implementations other than CPython.
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Sep 10, 2023
…ory (pythonGH-109233)

Fix test_pyexpat.test_exception(): it can now be run from a directory
different than Python source code directory. Before, the test failed
in this case.

Skip the test if Modules/pyexpat.c source is not available. Skip also
the test on Python implementations other than CPython.
(cherry picked from commit e55aab9)

Co-authored-by: Victor Stinner <vstinner@python.org>
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Sep 10, 2023
…ory (pythonGH-109233)

Fix test_pyexpat.test_exception(): it can now be run from a directory
different than Python source code directory. Before, the test failed
in this case.

Skip the test if Modules/pyexpat.c source is not available. Skip also
the test on Python implementations other than CPython.
(cherry picked from commit e55aab9)

Co-authored-by: Victor Stinner <vstinner@python.org>
vstinner added a commit that referenced this issue Sep 10, 2023
…tory (GH-109233) (#109242)

gh-109230: test_pyexpat no longer depends on the current directory (GH-109233)

Fix test_pyexpat.test_exception(): it can now be run from a directory
different than Python source code directory. Before, the test failed
in this case.

Skip the test if Modules/pyexpat.c source is not available. Skip also
the test on Python implementations other than CPython.
(cherry picked from commit e55aab9)

Co-authored-by: Victor Stinner <vstinner@python.org>
Yhg1s pushed a commit that referenced this issue Sep 12, 2023
…tory (GH-109233) (#109241)

gh-109230: test_pyexpat no longer depends on the current directory (GH-109233)

Fix test_pyexpat.test_exception(): it can now be run from a directory
different than Python source code directory. Before, the test failed
in this case.

Skip the test if Modules/pyexpat.c source is not available. Skip also
the test on Python implementations other than CPython.
(cherry picked from commit e55aab9)

Co-authored-by: Victor Stinner <vstinner@python.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tests Tests in the Lib/test dir type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

1 participant