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

KeyError: 'portal' in tests with Python 3.12.1 #1740

Closed
wesleybl opened this issue Dec 18, 2023 · 10 comments · Fixed by #1741 or #1756
Closed

KeyError: 'portal' in tests with Python 3.12.1 #1740

wesleybl opened this issue Dec 18, 2023 · 10 comments · Fixed by #1741 or #1756

Comments

@wesleybl
Copy link
Member

Tests with Python 3.12.1 are failing:

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: zopefoundation/Zope#1188

I suggest forcing the tests to run with Python 3.12.0, as long as the problem is not fixed.

@wesleybl
Copy link
Member Author

@Akshat2Jain can you please create a PR for this?

@Akshat2Jain
Copy link
Member

sorry @wesleybl for the late response, I have exams going on at my school! :(

@icemac
Copy link

icemac commented Dec 22, 2023

I do not think this has to do with zopefoundation/Zope#1188. (There we see another traceback.)
This is probably another problem with Python 3.12.1.

@wesleybl
Copy link
Member Author

@icemac you are right. I pinned zope.testrunner = 6.2.1 and the same error occurred. Maybe something needs to be changed in plone.app.testing.

@mauritsvanrees FYI.

@davisagli
Copy link
Member

@wesleybl It looks like this could happen if there was actually an error while setting up the test, so that "portal" never got set as an item on the layer.

Probably that testTearDown method should be a bit more careful. But, will that reveal the original error, or is it swallowed? I'm not sure.

@davisagli
Copy link
Member

I did some debugging; this is related to python/cpython#113267

@davisagli
Copy link
Member

Reopening since we worked around the issue rather than solving it

@davisagli davisagli reopened this Jan 5, 2024
@wesleybl
Copy link
Member Author

@davisagli while python/cpython#113267 is not fixed, we can make a test here to make sure the portal exists?

@davisagli
Copy link
Member

@wesleybl I started to do that, but then found that other similar fixes were needed for other layer resources.

@davisagli
Copy link
Member

@wesleybl The change in Python was reverted a few days ago, so I guess it'll be in the next patch release of Python 3.12

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