Repository: plone/plone.restapi (language: python)

Issue:
KeyError: 'portal' in tests with Python 3.12.1
Tests with Python 3.12.1 are failing:

```bash
Traceback (most recent call last):
  File "/home/runner/work/plone.restapi/plone.restapi/bin/test", line 289, in <module>
    sys.exit(zope.testrunner.run((['-s', 'plone.restapi', '--auto-color', '--auto-progress']) + [
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/runner/work/plone.restapi/plone.restapi/eggs/zope.testrunner-6.1-py3.12.egg/zope/testrunner/__init__.py", line 31, in run
    failed = run_internal(defaults, args, script_parts=script_parts, cwd=cwd,
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/runner/work/plone.restapi/plone.restapi/eggs/zope.testrunner-6.1-py3.12.egg/zope/testrunner/__init__.py", line 55, in run_internal
    runner.run()
  File "/home/runner/work/plone.restapi/plone.restapi/eggs/zope.testrunner-6.1-py3.12.egg/zope/testrunner/runner.py", line 191, in run
    self.run_tests()
  File "/home/runner/work/plone.restapi/plone.restapi/eggs/zope.testrunner-6.1-py3.12.egg/zope/testrunner/runner.py", line 292, in run_tests
    self.ran += run_layer(self.options, layer_name, layer, tests,
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/runner/work/plone.restapi/plone.restapi/eggs/zope.testrunner-6.1-py3.12.egg/zope/testrunner/runner.py", line 473, in run_layer
    return run_tests(options, tests, layer_name, failures, errors, skipped,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/runner/work/plone.restapi/plone.restapi/eggs/zope.testrunner-6.1-py3.12.egg/zope/testrunner/runner.py", line 399, in run_tests
    test(result)
  File "/opt/hostedtoolcache/Python/3.12.1/x64/lib/python3.12/unittest/case.py", line 692, in __call__
    return self.run(*args, **kwds)
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/hostedtoolcache/Python/3.12.1/x64/lib/python3.12/unittest/case.py", line 662, in run
    result.stopTest(self)
  File "/home/runner/work/plone.restapi/plone.restapi/eggs/zope.testrunner-6.1-py3.12.egg/zope/testrunner/runner.py", line 1019, in stopTest
    self.testTearDown()
  File "/home/runner/work/plone.restapi/plone.restapi/eggs/zope.testrunner-6.1-py3.12.egg/zope/testrunner/runner.py", line 891, in testTearDown
    layer.testTearDown()
  File "/home/runner/work/plone.restapi/plone.restapi/eggs/plone.app.testing-7.0.1-py3.12.egg/plone/app/testing/layers.py", line 291, in testTearDown
    self.tearDownEnvironment(self["portal"])
                             ~~~~^^^^^^^^^^
  File "/home/runner/work/plone.restapi/plone.restapi/eggs/plone.testing-8.0.4-py3.12.egg/plone/testing/layer.py", line 30, in __getitem__
    raise KeyError(key)
KeyError: 'portal'
```

See: https://github.com/plone/plone.restapi/actions/runs/7232945652/job/19707677378

When the tests were run with Python 3.12.0 they worked:

https://github.com/plone/plone.restapi/actions/runs/6999363538/job/19038558131#step:3:13

This appears to be related to: https://github.com/zopefoundation/Zope/issues/1188

I suggest forcing the tests to run with Python 3.12.0, as long as the problem is not fixed.


Discussion / hints:
@Akshat2Jain can you please create a PR for this?

Fix patch:
diff --git a/news/1740.internal b/news/1740.internal
new file mode 100644
index 0000000000..600bde22ef
--- /dev/null
+++ b/news/1740.internal
@@ -0,0 +1,1 @@
+Use Python 3.12.0 in tests to work around https://github.com/python/cpython/issues/113267. @wesleybl
\ No newline at end of file


Test patch:
diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml
index ebaa5eaa61..d677545c98 100644
--- a/.github/workflows/tests.yml
+++ b/.github/workflows/tests.yml
@@ -18,7 +18,8 @@ jobs:
             plone-version: "6.0"
           - python-version: "3.11"
             plone-version: "6.0"
-          - python-version: "3.12"
+          # FIXME: Change to 3.12 when https://github.com/python/cpython/issues/113267 is fixed
+          - python-version: "3.12.0"
             plone-version: "6.0"
     steps:
       # git checkout