diff --git a/src/fitz___init__.py b/src/fitz___init__.py index 95fc9ce4c..d8bc645fb 100644 --- a/src/fitz___init__.py +++ b/src/fitz___init__.py @@ -1,3 +1,5 @@ +import warnings + # pylint: disable=wildcard-import,unused-import,unused-wildcard-import,no-name-in-module from pymupdf import * from pymupdf import _as_fz_document @@ -12,4 +14,7 @@ from pymupdf import _globals from pymupdf import _g_out_message -message_warning('The `fitz` API is deprecated and will be removed in future. Use `import pymupdf` instead.') +warnings.warn( + 'The `fitz` API is deprecated and will be removed in future. Use `import pymupdf` instead.', + FutureWarning, + ) diff --git a/tests/test_general.py b/tests/test_general.py index 9dc2f25d6..3cc4ed29c 100644 --- a/tests/test_general.py +++ b/tests/test_general.py @@ -2281,3 +2281,37 @@ def test_5054(): assert text2 != text1 else: assert text2 == text1 + +def test_5100(): + print() + + def run(code): + code = textwrap.dedent(code) + print(f'code is:\n{textwrap.indent(code, " ")}') + path = os.path.normpath(f'{__file__}/../../tests/_test_5100.py') + with open(path, 'w') as f: + f.write(code) + cp = subprocess.run(f'{sys.executable} {path}', shell=1, check=1, capture_output=1) + print(f'{cp.stdout=}') + print(f'{cp.stderr=}') + return cp + + cp = run(''' + import pymupdf + ''') + assert cp.stdout == b'' + assert cp.stderr == b'' + + cp = run(''' + import fitz + ''') + assert cp.stdout == b'' + assert b'FutureWarning: The `fitz` API is deprecated and will be removed in future. Use `import pymupdf` instead' in cp.stderr + + cp = run(''' + import warnings + warnings.filterwarnings('ignore', category=FutureWarning, module='fitz') + import fitz + ''') + assert cp.stdout == b'' + assert cp.stderr == b''