bpo-46425: fix direct invocation of `test_contextlib` by sobolevn · Pull Request #30681 · python/cpython
There was a problem with direct invocation of test_contextlib. The best way to illustrate it is:
» ./python.exe Lib/test/test_contextlib.py
...................................................................................
----------------------------------------------------------------------
Ran 83 tests in 0.046s
OK
» ./python.exe ./Lib/test/test_contextlib.py
............................FFF....................................................
======================================================================
FAIL: test_exception (__main__.TestChdir)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Users/sobolev/Desktop/cpython/./Lib/test/test_contextlib.py", line 1159, in test_exception
self.assertEqual(os.getcwd(), target)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: '/Users/sobolev/Desktop/cpython/Lib/test/data' != '/Users/sobolev/Desktop/cpython/./Lib/test/data'
- /Users/sobolev/Desktop/cpython/Lib/test/data
+ /Users/sobolev/Desktop/cpython/./Lib/test/data
? ++
======================================================================
FAIL: test_reentrant (__main__.TestChdir)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Users/sobolev/Desktop/cpython/./Lib/test/test_contextlib.py", line 1143, in test_reentrant
self.assertEqual(os.getcwd(), target1)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: '/Users/sobolev/Desktop/cpython/Lib/test/data' != '/Users/sobolev/Desktop/cpython/./Lib/test/data'
- /Users/sobolev/Desktop/cpython/Lib/test/data
+ /Users/sobolev/Desktop/cpython/./Lib/test/data
? ++
======================================================================
FAIL: test_simple (__main__.TestChdir)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Users/sobolev/Desktop/cpython/./Lib/test/test_contextlib.py", line 1132, in test_simple
self.assertEqual(os.getcwd(), target)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: '/Users/sobolev/Desktop/cpython/Lib/test/data' != '/Users/sobolev/Desktop/cpython/./Lib/test/data'
- /Users/sobolev/Desktop/cpython/Lib/test/data
+ /Users/sobolev/Desktop/cpython/./Lib/test/data
? ++
----------------------------------------------------------------------
Ran 83 tests in 0.050s
FAILED (failures=3)
When __file__ is normalized - the error is gone. Now we can use both styles to call this module.