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

Python 3.12 support #272

Closed
grigi opened this issue Oct 3, 2023 · 4 comments · Fixed by #274
Closed

Python 3.12 support #272

grigi opened this issue Oct 3, 2023 · 4 comments · Fixed by #274

Comments

@grigi
Copy link

grigi commented Oct 3, 2023

Hi, I was testing the brand-new-released Py3.12 on common libraries I use, and green is failing to run tests with the following error:

Traceback (most recent call last):
  File "/mnt/old/home/grigi/work/magneto/.pyenv/bin/green", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/mnt/old/home/grigi/work/magneto/.pyenv/lib/python3.12/site-packages/green/cmdline.py", line 89, in main
    return _main(argv, testing)
           ^^^^^^^^^^^^^^^^^^^^
  File "/mnt/old/home/grigi/work/magneto/.pyenv/lib/python3.12/site-packages/green/cmdline.py", line 12, in _main
    args = config.mergeConfig(args, testing)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/mnt/old/home/grigi/work/magneto/.pyenv/lib/python3.12/site-packages/green/config.py", line 677, in mergeConfig
    config = getConfig(getattr(args, "config", default_args.config))
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/mnt/old/home/grigi/work/magneto/.pyenv/lib/python3.12/site-packages/green/config.py", line 648, in getConfig
    read_func = getattr(parser, "read_file", getattr(parser, "readfp"))
                                             ^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'ConfigParser' object has no attribute 'readfp'. Did you mean: 'read'?

It appears to be related to this change: https://docs.python.org/3.12/whatsnew/3.12.html#configparser

Running the tests with python -m unittest works as expected.

@sodul
Copy link
Collaborator

sodul commented Nov 22, 2023

I'm able to run tests with python 3.12.0 but I get a new warning.

import unittest

class DurationTestCase(unittest.TestCase):

    def test_pass(self):
        pass

And with Green we get:

> green test_vanilla.py
.

Captured stderr for test_vanilla.DurationTestCase.test_pass
/Users/stephane/.pyenv/versions/3.12.0/lib/python3.12/unittest/case.py:580: RuntimeWarning: TestResult has no addDuration method
  warnings.warn("TestResult has no addDuration method",

Ran 1 test in 0.221s using 10 processes

OK (passes=1)

@CleanCut I can probably take a look over the long weekend but if you are around I would like to discuss a few things:

  • get a new release out from the current main since there are some changes in the codebase.
  • drop support for python 3.7. It is deprecated and most folks have now dropped support for it. It will help because there is some logic for threads that changed in 3.8 and it confuses pylint/mypy.
  • improve the type annotation. I actually started this in a local branch but ran into issues with the pre-3.8 logic. It did discover getattr() bugs similar to the one reported here.

@sodul
Copy link
Collaborator

sodul commented Nov 28, 2023

This is not necessarily what I would PR, but this patch got the warnings to go away with Python 3.12.0:

--- result.py.orig      2023-11-28 12:33:02
+++ result.py   2023-11-28 12:41:44
@@ -172,6 +172,7 @@
         self.stderr_errput = OrderedDict()
         self.stream = stream
         self.colors = colors
+        self.collectedDurations = []

     def recordStdout(self, test, output):
         """
@@ -224,6 +225,17 @@
                 )
             )
             del self.stderr_errput[test]
+
+    def addDuration(self, test, elapsed):
+        """
+        Called when a test finished to run, regardless of its outcome.
+
+        Args:
+            test: The test case corresponding to the test method.
+            elapsed: The time represented in seconds, including the
+                execution of cleanup functions.
+        """
+        self.collectedDurations.append((str(test), elapsed))


 class ProtoTestResult(BaseTestResult):
@@ -255,6 +267,7 @@
     def reinitialize(self):
         self.shouldStop = False
         self.errors = []
+        self.collectedDurations = []
         self.expectedFailures = []
         self.failures = []
         self.passing = []
@@ -399,6 +412,7 @@
         self.shouldStop = False
         self.testsRun = 0
         # Individual lists
+        self.collectedDurations = []
         self.errors = []
         self.expectedFailures = []
         self.failures = []

Posting here so others can get unstuck while a new release can get published with a full fix.

@CleanCut
Copy link
Owner

CleanCut commented Dec 2, 2023

@sodul Cool! Feel free to open up a PR. 👍

@CleanCut
Copy link
Owner

CleanCut commented Dec 2, 2023

Sidenote: Sorry for the delay(s) in my response(s). I'm going through some major life changes at the moment which are consuming all of my time. I'll try to check in more often, and I welcome all the help I can get.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants