Repository: meejah/txtorcon (language: python)

Issue:
Three unit tests are failing on Python 3.12
All unit tests (except those skipped) pass on Python 3.11.3, but three are failing on Python 3.12.0 beta 1.

If it's relevant, this is with Twisted 22.10.0.

```
===============================================================================
[SKIPPED]
No GeoIP in github-actions

test.test_util.TestGeoIpDatabaseLoading.test_return_geoip_object
===============================================================================
[SKIPPED]
Doesn't work in PYPY, Py3

test.test_util_imports.TestImports.test_no_GeoIP
===============================================================================
[FAIL]
Traceback (most recent call last):
  File "/var/tmp/portage/dev-python/txtorcon-23.5.0/work/txtorcon-23.5.0/test/test_torstate.py", line 1296, in test_build_circuit
    self.assertEqual(len(self.flushWarnings()), 1)
  File "/usr/lib/python3.12/site-packages/twisted/trial/_synctest.py", line 441, in assertEqual
    super().assertEqual(first, second, msg)
  File "/usr/lib/python3.12/unittest/case.py", line 885, in assertEqual
    assertion_func(first, second, msg=msg)
  File "/usr/lib/python3.12/unittest/case.py", line 878, in _baseAssertEqual
    raise self.failureException(msg)
twisted.trial.unittest.FailTest: 3 != 1

test.test_torstate.StateTests.test_build_circuit
===============================================================================
[FAIL]
Traceback (most recent call last):
  File "/var/tmp/portage/dev-python/txtorcon-23.5.0/work/txtorcon-23.5.0/test/test_torstate.py", line 1332, in test_build_circuit_final_callback
    self.assertEqual(len(self.flushWarnings()), 1)
  File "/usr/lib/python3.12/site-packages/twisted/trial/_synctest.py", line 441, in assertEqual
    super().assertEqual(first, second, msg)
  File "/usr/lib/python3.12/unittest/case.py", line 885, in assertEqual
    assertion_func(first, second, msg=msg)
  File "/usr/lib/python3.12/unittest/case.py", line 878, in _baseAssertEqual
    raise self.failureException(msg)
twisted.trial.unittest.FailTest: 5 != 1

test.test_torstate.StateTests.test_build_circuit_final_callback
===============================================================================
[FAIL]
Traceback (most recent call last):
  File "/var/tmp/portage/dev-python/txtorcon-23.5.0/work/txtorcon-23.5.0/test/test_torstate.py", line 1480, in test_build_circuit_not_timedout
    self.assertEqual(len(self.flushWarnings()), 1)
  File "/usr/lib/python3.12/site-packages/twisted/trial/_synctest.py", line 441, in assertEqual
    super().assertEqual(first, second, msg)
  File "/usr/lib/python3.12/unittest/case.py", line 885, in assertEqual
    assertion_func(first, second, msg=msg)
  File "/usr/lib/python3.12/unittest/case.py", line 878, in _baseAssertEqual
    raise self.failureException(msg)
twisted.trial.unittest.FailTest: 7 != 1

test.test_torstate.StateTests.test_build_circuit_not_timedout
-------------------------------------------------------------------------------
Ran 682 tests in 2.863s

FAILED (skips=2, failures=3, successes=677)
```


Discussion / hints:

Fix patch:
diff --git a/docs/releases.rst b/docs/releases.rst
index 64618aa7..defd46f2 100644
--- a/docs/releases.rst
+++ b/docs/releases.rst
@@ -17,6 +17,7 @@ See also :ref:`api_stability`.
 
 `git main <https://github.com/meejah/txtorcon>`_ *will likely become v23.6.0*
 
+ * Fix test-failures on Python 3.12
 
 
 v23.5.0


Test patch:
diff --git a/test/test_torstate.py b/test/test_torstate.py
index 77c930a8..7a41ecf2 100644
--- a/test/test_torstate.py
+++ b/test/test_torstate.py
@@ -1293,7 +1293,14 @@ def __init__(self, i):
         self.assertEqual(self.transport.value(), b'EXTENDCIRCUIT 0 0000000000000000000000000000000000000000,0000000000000000000000000000000000000001,0000000000000000000000000000000000000002\r\n')
         # should have gotten a warning about this not being an entry
         # guard
-        self.assertEqual(len(self.flushWarnings()), 1)
+        self.assertEqual(
+            1,
+            len([
+                warn
+                for warn in self.flushWarnings()
+                if "Circuit doesn't start with a guard" in warn["message"]
+            ])
+        )
 
     def test_build_circuit_no_routers(self):
         self.state.build_circuit()
@@ -1329,7 +1336,14 @@ def __init__(self, i):
         self.send(b"250 EXTENDED 1234")
         # should have gotten a warning about this not being an entry
         # guard
-        self.assertEqual(len(self.flushWarnings()), 1)
+        self.assertEqual(
+            1,
+            len([
+                warn
+                for warn in self.flushWarnings()
+                if "Circuit doesn't start with a guard" in warn["message"]
+            ])
+        )
         return d
 
     def test_build_circuit_error(self):
@@ -1477,7 +1491,14 @@ def __init__(self, i):
         self.state.circuits[1234].update(['1234', 'BUILT'])
         # should have gotten a warning about this not being an entry
         # guard
-        self.assertEqual(len(self.flushWarnings()), 1)
+        self.assertEqual(
+            1,
+            len([
+                warn
+                for warn in self.flushWarnings()
+                if "Circuit doesn't start with a guard" in warn["message"]
+            ])
+        )
         return d
 
     def test_build_circuit_failure(self):