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

avocado/core/loader.py: support Python 3.12 by using importlib #5727

Merged
merged 4 commits into from
Jul 17, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ jobs:
run: python -c "import sys; print(sys.version)"
- name: Install dependencies
run: pip install -r requirements-dev.txt
- name: Install Python 3.6 compatible urllib3
if: ${{ matrix.python-version == 3.6 }}
run: python3 -m pip install urllib3==1.26.16
- name: Installing Avocado in develop mode
run: python3 setup.py develop --user
- name: Avocado version
Expand Down
10 changes: 6 additions & 4 deletions avocado/core/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
Test loader module.
"""

import imp
import importlib
import inspect
import os
import re
Expand Down Expand Up @@ -281,11 +281,13 @@ def load_test(test_factory):
if isinstance(test_class, str):
module_name = os.path.basename(test_path).split('.')[0]
test_module_dir = os.path.abspath(os.path.dirname(test_path))
# Tests with local dir imports need this
try:
spec = importlib.util.spec_from_file_location(module_name, test_path)
test_module = importlib.util.module_from_spec(spec)
sys.modules[module_name] = test_module
# Tests with local dir imports need this
sys.path.insert(0, test_module_dir)
f, p, d = imp.find_module(module_name, [test_module_dir])
test_module = imp.load_module(module_name, f, p, d)
spec.loader.exec_module(test_module)
except: # pylint: disable=W0702
# On load_module exception we fake the test class and pass
# the exc_info as parameter to be logged.
Expand Down
2 changes: 1 addition & 1 deletion optional_plugins/robot/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
packages=find_packages(),
include_package_data=True,
install_requires=['avocado-framework==%s' % VERSION,
'robotframework>=4.1'],
'robotframework>=4.1,<6.0'],
test_suite='tests',
entry_points={
'console_scripts': [
Expand Down