changeset 52135:cf8d029a480b

tests: skip doctests that use `time.tzset()` on Windows There's no way to conditionally skip the tests for a function (see the inline feature request). That leaves us with the choice to either put the whole `mercurial.utils.dateutil` module in the skip list of this script (but then this script prints out the module as unexpectedly not tested, and misses a bunch of tests that can be run), blacklist the test entirely (but that makes it harder to work with on Windows), or use this hack to look for the statement that is broken, and skip the test currently attached to one function. (It appears that an example in the list of examples corresponds to a single `>>>` block, and the `test` itself corresponds to a single function. So prescan the examples, and skip all of them when the statement is found in any, since the setup of setting the timezone has an effect on subsequent examples.)
author Matt Harbison <matt_harbison@yahoo.com>
date Sun, 27 Oct 2024 17:29:18 -0400
parents 479899e53816
children c33734fbcd4b
files tests/test-doctest.py
diffstat 1 files changed, 11 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/tests/test-doctest.py	Mon Oct 07 12:08:48 2024 +0100
+++ b/tests/test-doctest.py	Sun Oct 27 17:29:18 2024 -0400
@@ -43,7 +43,17 @@
     checker = py3docchecker()
     runner = doctest.DocTestRunner(checker=checker, optionflags=optionflags)
     for test in finder.find(mod, name):
-        runner.run(test)
+        # Windows doesn't have time.tzset(), so skip methods that invoke it in
+        # a doctest, without hardcoding the function name.  There is a feature
+        # request for adding syntax to the test itself to conditionally skip
+        # that would make this unnecessary:
+        #
+        # https://github.com/python/cpython/issues/117364
+        for example in test.examples:
+            if os.name == 'nt' and 'time.tzset()' in example.source:
+                break
+        else:
+            runner.run(test)
     runner.summarize()