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

fix under python 3.11+ #350

Merged
merged 3 commits into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"Development Status :: 4 - Beta",
],
install_requires=['mock', 'six>=1.7.3'],
python_requires='>=3.8',
packages=["testify", "testify.contrib", "testify.utils", "testify.plugins"],
scripts=['bin/testify'],
long_description="""Testify - A Testing Framework
Expand Down
8 changes: 7 additions & 1 deletion test/discovery_failure_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,11 @@ def test_discover_test_with_broken_import(self):
r' Traceback \(most recent call last\):\n'
r' File "[^"]+", line \d+, in discover\n'
r' submod = __import__\(module_name, fromlist=\[str\(\'__trash\'\)\]\)\n'
r'( \^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^'
r'\^\^\^\^\n)?'
r' File "[^"]+", line \d+, in <module>\n'
r' import non_existent_module \# noqa: F401\n'
r'( \^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\n)?'
r' (ModuleNotFoundError|ImportError): No module named \'?non_existent_module\'?\n'
),
)
Expand All @@ -48,11 +51,14 @@ def test_discover_test_with_broken_import(self):
T.assert_equal(
stderr,
RegexMatcher(
r'Traceback \(most recent call last\):\n'
r'(Traceback \(most recent call last\):\n)?'
r' File .+, line \d+, in discover\n'
r" submod = __import__\(module_name, fromlist=\[str\(\'__trash\'\)\]\)\n"
r'( \^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^'
r'\^\^\n)?'
r' File .+, line \d+, in <module>\n'
r' import non_existent_module \# noqa: F401\n'
r'( \^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\n)?'
r"(ModuleNotFoundError|ImportError): No module named '?non_existent_module'?\n"
),
)
Expand Down
4 changes: 2 additions & 2 deletions test/test_runner_test.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import imp
import mock
from testify import assert_equal
from testify import setup
from testify import setup_teardown
from testify import test_case
from testify import test_runner
from types import ModuleType

from .test_runner_subdir.inheriting_class import InheritingClass

Expand Down Expand Up @@ -59,7 +59,7 @@ class PluginTestCase(test_case.TestCase):
"""
@setup
def build_module(self):
self.our_module = imp.new_module("our_module")
self.our_module = ModuleType("our_module")
setattr(self.our_module, "prepare_test_case", prepare_test_case)
setattr(self.our_module, "run_test_case", run_test_case)
setattr(self.our_module, "add_testcase_info", add_testcase_info)
Expand Down
13 changes: 3 additions & 10 deletions testify/test_program.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import pprint
import sys
import logging
import imp
from importlib.machinery import SourceFileLoader

import testify
from testify import exit
Expand All @@ -46,11 +46,6 @@ def load_plugins():
# The idea will be to check out the directory contents and pick up any files that seem to match what python knows how to
# import.

# To properly load the module, we'll need to identify what type it is by the file extension
suffix_map = {}
for suffix in imp.get_suffixes():
suffix_map[suffix[0]] = suffix

plugin_directories = [DEFAULT_PLUGIN_PATH]
if 'TESTIFY_PLUGIN_PATH' in os.environ:
plugin_directories += os.environ['TESTIFY_PLUGIN_PATH'].split(':')
Expand All @@ -60,16 +55,14 @@ def load_plugins():
for file_name in os.listdir(plugin_path):

# For any file that we know how to load, try to import it
if any(file_name.endswith('.py') and not file_name.startswith('.') for suffix in suffix_map.keys()):
if file_name.endswith('.py') and not file_name.startswith('.'):
full_file_path = os.path.join(plugin_path, file_name)
mod_name, suffix = os.path.splitext(file_name)
# Need some unlikely-to-clash unique-ish module name
mod_name = '_testify_plugin__' + mod_name

try:
plugin_modules.append(
imp.load_source(mod_name, full_file_path),
)
SourceFileLoader(mod_name, full_file_path).load_module()
except TypeError:
continue
except ImportError as e:
Expand Down