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

gh-111912: Run test_posix on Windows #111913

Merged
merged 3 commits into from
Nov 10, 2023

Conversation

serhiy-storchaka
Copy link
Member

@serhiy-storchaka serhiy-storchaka commented Nov 9, 2023

@@ -1220,6 +1227,7 @@ def test_sched_setaffinity(self):
self.assertRaises(OSError, posix.sched_setaffinity, -1, mask)

@unittest.skipIf(support.is_wasi, "No dynamic linking on WASI")
@unittest.skipUnless(os.name == 'posix', "requires Posix")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test is called "posix" and other tests are run. It's surprising that a test is skipped because it "requires Posix".

Maybe skip the test on Windows, is support.MS_WINDOWS is true? With a message like "Windows doesn't have RTLD constants".

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The message for the skip test as is would better be "requires posix module". But I think Victor's suggest is even better. It there were a 3rd OS module, we don't know that the test would need to be skipped.

Copy link
Member Author

@serhiy-storchaka serhiy-storchaka Nov 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not invent this message, it is one of common messages already used in many other tests with this condition. Grep 'skip.*posix'. Other common messages are "only supported on Unix" (technically incorrect, Linux is not Unix), 'tests requires a posix system.', "test meaningful only on posix systems", 'POSIX-only test', 'POSIX only test'. Only one of them spells "Posix" correctly.

But unification of skipping messages is a matter of different issue.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Windows provides a POSIX-like API for many years. You say that Linux is not Unix. Well, I would still prefer to say "Windows doesn't have RTLD constants" than just "requires Posix". By the way, POSIX is an accronym which stands for "Portable Operating System Interface", and so should be written in uppercase: https://en.wikipedia.org/wiki/POSIX ;-)

Python is misleading since os.name is just "posix" on all platforms but Windows (where it's "nt"): https://pythondev.readthedocs.io/platforms.html#sys-platform-versus-os-name Is it the name of the operating system ("OS") or the name of the C extension? The "os" name is not called "os?" :-)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I must have confused him with FORTRAN that is now simply Fortran.

try:
import nt as posix
except ImportError:
raise unittest.SkipTest("requires 'posix' or 'nt' module")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hum, when is this code path supposed to be taken? On Python implementations other than CPython? If the compilation of the posix/nt extension failed?

I would prefer to get an ImportError rather than skipping silently the test. If there is a legit use case to skip the test, in that ok, sure, we can skip it. But now it's unclear to me why posix and nt would miss.

PyPy has a posix module on Linux for example.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not know, but maybe on some custom builds of Python on some exotic platforms.

Currently the os module only supports posix and nt.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not know, but maybe on some custom builds of Python on some exotic platforms.

If someone has a custom build of Python, I suppose that they can modify one line of test_posix.py to skip the whole file on their exotic platform. I would prefer to be safe by default. For me, it's more likely that the test would be skipped by mistake, than causing troubles on exotic platforms. Also, we don't support exotic platforms (PEP 11).

@terryjreedy
Copy link
Member

There is currently a test_ntpath corresponding to test_posixpath and a test_os for os functions not part the Posix standard, but no test_nt corresponding to test_posix. So this fill what seems a gap in testing the Posix functions in 'nt', and with minimal fuss. +1 except possibly for details.

@vstinner
Copy link
Member

I'm considering the split test_os into a test package and sub-files. Maybe test_os, test_posix, test_ntpath, etc. can be moved there. But that's should be done later.

Copy link
Member

@vstinner vstinner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

try:
import posix
except ImportError:
import nt as posix
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a little bit surprising, but well, it's convenient for these tests :-)

The C extension should be called _os instead of posix or nt :-(

@serhiy-storchaka
Copy link
Member Author

Thank you Victor and Terry for your review.

@serhiy-storchaka serhiy-storchaka merged commit 64fea32 into python:main Nov 10, 2023
22 checks passed
@miss-islington-app
Copy link

Thanks @serhiy-storchaka for the PR 🌮🎉.. I'm working now to backport this PR to: 3.11, 3.12.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Nov 10, 2023
(cherry picked from commit 64fea32)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Nov 10, 2023
(cherry picked from commit 64fea32)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
@bedevere-app
Copy link

bedevere-app bot commented Nov 10, 2023

GH-111953 is a backport of this pull request to the 3.12 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.12 bug and security fixes label Nov 10, 2023
@bedevere-app
Copy link

bedevere-app bot commented Nov 10, 2023

GH-111954 is a backport of this pull request to the 3.11 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.11 only security fixes label Nov 10, 2023
serhiy-storchaka added a commit that referenced this pull request Nov 10, 2023
(cherry picked from commit 64fea32)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
serhiy-storchaka added a commit that referenced this pull request Nov 10, 2023
(cherry picked from commit 64fea32)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
@serhiy-storchaka serhiy-storchaka deleted the win-test_posix branch November 10, 2023 15:10
aisk pushed a commit to aisk/cpython that referenced this pull request Feb 11, 2024
Glyphack pushed a commit to Glyphack/cpython that referenced this pull request Sep 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
skip news tests Tests in the Lib/test dir
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants