From 00a8ed3c17f601f52f9bbfd0eda31bb125d003f3 Mon Sep 17 00:00:00 2001 From: Thomas Holder Date: Thu, 20 Jul 2023 22:42:00 +0200 Subject: [PATCH 1/3] Support running all tests with pytest --- testing/conftest.py | 8 ++++++++ testing/pytest.ini | 5 +++++ testing/testing.py | 5 +---- 3 files changed, 14 insertions(+), 4 deletions(-) create mode 100644 testing/conftest.py diff --git a/testing/conftest.py b/testing/conftest.py new file mode 100644 index 000000000..1d32e1174 --- /dev/null +++ b/testing/conftest.py @@ -0,0 +1,8 @@ +import pymol + +pymol.__path__.append(".") +pymol.__path__.append("tests/helpers") + +collect_ignore = [ + "tests/helpers", +] diff --git a/testing/pytest.ini b/testing/pytest.ini index c24fe5bb9..c009d1c89 100644 --- a/testing/pytest.ini +++ b/testing/pytest.ini @@ -1,3 +1,8 @@ [pytest] filterwarnings = ignore::DeprecationWarning +addopts = + --import-mode=importlib +testpaths = tests +python_files = + *.py diff --git a/testing/testing.py b/testing/testing.py index b45047cfe..1b6ba1048 100644 --- a/testing/testing.py +++ b/testing/testing.py @@ -377,8 +377,6 @@ class PyMOLTestCase(PyMOLTestCaseMeta("Base", (unittest.TestCase,), {})): assertEquals = unittest.TestCase.assertEqual assertItemsEqual = unittest.TestCase.assertCountEqual - moddirs = {} - def setUp(self): self.oldcwd = os.getcwd() cmd.reinitialize() @@ -387,7 +385,7 @@ def setUp(self): if cliargs.no_undo: cmd.set('suspend_undo', updates=0) - cwd = self.moddirs[type(self).__module__] + cwd = os.path.dirname(inspect.getfile(type(self))) os.chdir(cwd) cmd.feedback('push') @@ -679,7 +677,6 @@ def run_testfiles(filenames='all', verbosity=2, out=sys.stderr, **kwargs): # hacky: register working directory with test cases dirname = os.path.abspath(os.path.dirname(filename)) - PyMOLTestCase.moddirs[mod.__name__] = dirname suite.addTest(unittest.defaultTestLoader .loadTestsFromModule(mod)) From bd4e3ab91f2d5f8570120d492b3ed345e84268c6 Mon Sep 17 00:00:00 2001 From: Thomas Holder Date: Fri, 1 Sep 2023 07:43:31 +0200 Subject: [PATCH 2/3] Make --no-mmlibs --no-undo the default These tests seem unsupported by modern PyMOL versions (like 2.5.6), see https://github.com/schrodinger/pymol-testing/issues/9 Add `--with-mmlibs` and `--with-undo` options to enable these tests. --- testing/testing.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/testing/testing.py b/testing/testing.py index 1b6ba1048..eea78ba5c 100644 --- a/testing/testing.py +++ b/testing/testing.py @@ -104,8 +104,10 @@ def tupleize_version(strversion): parser.add_argument('filenames', nargs='*', default=[]) parser.add_argument('--out', default=sys.stdout) parser.add_argument('--offline', action='store_true') - parser.add_argument('--no-mmlibs', action='store_true') - parser.add_argument('--no-undo', action='store_true') + parser.add_argument('--no-mmlibs', action='store_true', default=True) + parser.add_argument('--with-mmlibs', action='store_false', dest='no_mmlibs') + parser.add_argument('--no-undo', action='store_true', default=True) + parser.add_argument('--with-undo', action='store_false', dest='no_undo') parser.add_argument('--verbosity', type=int, default=2) have_dash_dash = __file__.startswith(sys.argv[0]) or '--run' in sys.argv From d4d27a347ba67b3cef521006b823a3b9576d4c8e Mon Sep 17 00:00:00 2001 From: Thomas Holder Date: Fri, 1 Sep 2023 08:34:48 +0200 Subject: [PATCH 3/3] Require PyMOL 2.6 for testLoadPLY --- testing/tests/api/importing.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testing/tests/api/importing.py b/testing/tests/api/importing.py index 6e19ac2d8..e302dabc9 100644 --- a/testing/tests/api/importing.py +++ b/testing/tests/api/importing.py @@ -529,7 +529,7 @@ def testLoadPDBQT(self): 0.21, -0.644, -0.644] self.assertArrayEqual(charges, charges_expected, delta=1e-4) - @testing.requires_version('1.8.3.1') + @testing.requires_version('2.6') def testLoadPLY(self): cmd.load(self.datafile("test_PHE_pentamer.ply.gz")) e = cmd.get_extent('test_PHE_pentamer')