diff --git a/test/jpypetest/common.py b/test/jpypetest/common.py index 9531c615f..6b987c6f9 100644 --- a/test/jpypetest/common.py +++ b/test/jpypetest/common.py @@ -15,6 +15,7 @@ # See NOTICE file for details. # # ***************************************************************************** +from functools import lru_cache import pytest import _jpype @@ -142,3 +143,15 @@ def assertElementsAlmostEqual(self, a, b): def useEqualityFunc(self, func): return UseFunc(self, func, 'assertEqual') + + +@lru_cache(1) +def java_version(): + import subprocess + import sys + java_version = str(subprocess.check_output([sys.executable, "-c", + "import jpype; jpype.startJVM(); " + "print(jpype.java.lang.System.getProperty('java.version'))"]), + encoding='ascii') + print("java_version:", java_version) + return tuple(map(int, java_version.split("."))) diff --git a/test/jpypetest/conftest.py b/test/jpypetest/conftest.py index 051cff752..e613f87d9 100755 --- a/test/jpypetest/conftest.py +++ b/test/jpypetest/conftest.py @@ -15,7 +15,6 @@ # See NOTICE file for details. # # ***************************************************************************** -from functools import cache import pytest @@ -46,13 +45,3 @@ def common_opts(request): request.cls._convertStrings = request.config.getoption("--convertStrings") request.cls._jacoco = request.config.getoption("--jacoco") request.cls._checkjni = request.config.getoption("--checkjni") - - -#@pytest.fixture(scope="session", autouse=True) -@cache -def java_version(): - print("hi from java_version()") - import subprocess, sys - java_version = str(subprocess.check_output([sys.executable, "-c", - "import jpype; jpype.startJVM(); print(jpype.java.lang.System.getProperty('java.version'))"])) - return java_version.split(".") diff --git a/test/jpypetest/test_sql_sqlite.py b/test/jpypetest/test_sql_sqlite.py index f845f75c9..c485f680e 100644 --- a/test/jpypetest/test_sql_sqlite.py +++ b/test/jpypetest/test_sql_sqlite.py @@ -22,10 +22,10 @@ db_name = "jdbc:sqlite::memory:" def setUpModule(module): - from conftest import java_version + from common import java_version version = java_version() print("setup module: jdk version", version) - if version[0] == "8": + if version[0] == 8: pytest.skip("jdk8 unsupported", allow_module_level=True) # raise common.unittest.SkipTest("SQLite unsupported for JDK 8.")