diff --git a/scripts/test.py b/scripts/test.py index 8d9832e99..ee4b53bbe 100755 --- a/scripts/test.py +++ b/scripts/test.py @@ -927,9 +927,12 @@ def cibuildwheel( # will notice that the wheel we built above supports all versions of # Python, so will not actually do any builds here. # - env_extra['CIBW_BUILD'] = CIBW_BUILD - run(f'cd {pymupdf_dir} && cibuildwheel{cibw_pyodide_args}', env_extra=env_extra) - run(f'ls -ld {pymupdf_dir}/wheelhouse/*') + # We only do this if there are more than one Python versions. This still + # duplicates the testing of the first python version. + if len(CIBW_BUILD.split()) > 1: + env_extra['CIBW_BUILD'] = CIBW_BUILD + run(f'cd {pymupdf_dir} && cibuildwheel{cibw_pyodide_args}', env_extra=env_extra) + run(f'ls -ld {pymupdf_dir}/wheelhouse/*') def cibw_do_test_project(env_extra, CIBW_BUILD, cibw_pyodide, cibw_pyodide_args): diff --git a/tests/conftest.py b/tests/conftest.py index e1d02297a..06af5b7aa 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -77,11 +77,25 @@ def get_members(a): # Allow post-test checking that pymupdf._globals has not changed. _globals_pre = get_members(pymupdf._globals) + testsfailed_before = request.session.testsfailed + # Run the test. rep = yield sys.stdout.flush() + # This seems the only way for us to tell that a test has failed. In + # particular, is always None. We're implicitly relying on tests not + # being run in parallel. + # + failed = request.session.testsfailed - testsfailed_before + assert failed in (0, 1) + + if failed: + # Do not check post-test conditions if the test as failed. This avoids + # additional confusing `ERROR` status for failed tests. + return + # Test has run; check it did not create any MuPDF warnings etc. wt = pymupdf.TOOLS.mupdf_warnings() if not hasattr(pymupdf, 'mupdf'): diff --git a/tests/test_tesseract.py b/tests/test_tesseract.py index a36120cce..7650e8381 100644 --- a/tests/test_tesseract.py +++ b/tests/test_tesseract.py @@ -15,10 +15,6 @@ def test_tesseract(): But if TESSDATA_PREFIX is set in the environment, we assert that FzPage.get_textpage_ocr() succeeds. ''' - if os.environ.get('PYODIDE_ROOT'): - print('test_tesseract(): not running on Pyodide - cannot run child processes.') - return - path = os.path.abspath( f'{__file__}/../resources/2.pdf') doc = pymupdf.open( path) page = doc[5] @@ -28,14 +24,18 @@ def test_tesseract(): tail = 'OCR initialisation failed' else: tail = 'Tesseract language initialisation failed' - e_expected = f'code=3: {tail}' - if platform.system() == 'OpenBSD': - # 2023-12-12: For some reason the SWIG catch code only catches - # the exception as FzErrorBase. - e_expected_type = pymupdf.mupdf.FzErrorBase - print(f'OpenBSD workaround - expecting FzErrorBase, not FzErrorLibrary.') + if os.environ.get('PYODIDE_ROOT'): + e_expected = 'code=6: No OCR support in this build' + e_expected_type = pymupdf.mupdf.FzErrorUnsupported else: - e_expected_type = pymupdf.mupdf.FzErrorLibrary + e_expected = f'code=3: {tail}' + if platform.system() == 'OpenBSD': + # 2023-12-12: For some reason the SWIG catch code only catches + # the exception as FzErrorBase. + e_expected_type = pymupdf.mupdf.FzErrorBase + print(f'OpenBSD workaround - expecting FzErrorBase, not FzErrorLibrary.') + else: + e_expected_type = pymupdf.mupdf.FzErrorLibrary else: # classic. e_expected = 'OCR initialisation failed'