]> git.ipfire.org Git - thirdparty/babel.git/commitdiff
Quiesce pytest warnings (#916)
authorAarni Koskela <akx@iki.fi>
Tue, 1 Nov 2022 10:16:04 +0000 (12:16 +0200)
committerGitHub <noreply@github.com>
Tue, 1 Nov 2022 10:16:04 +0000 (12:16 +0200)
* Skip doctest of deprecated format_number

* Don't return from test_compatible_classes_in_global_and_localedata

* Renovate conftest (and require pytest 6+)

babel/numbers.py
conftest.py
tests/test_core.py
tox.ini

index 192e3ed6e04fd422872ed244dfb69e62e31d3223..373a9bd1657aa488ceb1efdaeeb3fd58d58b7997 100644 (file)
@@ -338,9 +338,9 @@ def get_group_symbol(locale=LC_NUMERIC):
 def format_number(number, locale=LC_NUMERIC):
     u"""Return the given number formatted for a specific locale.
 
-    >>> format_number(1099, locale='en_US')
+    >>> format_number(1099, locale='en_US')  # doctest: +SKIP
     u'1,099'
-    >>> format_number(1099, locale='de_DE')
+    >>> format_number(1099, locale='de_DE')  # doctest: +SKIP
     u'1.099'
 
     .. deprecated:: 2.6.0
index bd9f2d32d276a6ab30781d4d4b9b49d0a0faa498..3982cef4e1d1a15d72d41e236aef57819b691d06 100644 (file)
@@ -1,14 +1,20 @@
+from pathlib import Path
+
 from _pytest.doctest import DoctestModule
-from py.path import local
 
 collect_ignore = ['tests/messages/data', 'setup.py']
-babel_path = local(__file__).dirpath().join('babel')
+babel_path = Path(__file__).parent / 'babel'
+
+
+# Via the stdlib implementation of Path.is_relative_to in Python 3.9
+def _is_relative(p1: Path, p2: Path) -> bool:
+    try:
+        p1.relative_to(p2)
+        return True
+    except ValueError:
+        return False
 
 
-def pytest_collect_file(path, parent):
-    if babel_path.common(path) == babel_path:
-        if path.ext == ".py":
-            # TODO: remove check when dropping support for old Pytest
-            if hasattr(DoctestModule, "from_parent"):
-                return DoctestModule.from_parent(parent, fspath=path)
-            return DoctestModule(path, parent)
+def pytest_collect_file(file_path: Path, parent):
+    if _is_relative(file_path, babel_path) and file_path.suffix == '.py':
+        return DoctestModule.from_parent(parent, path=file_path)
index 529a424a00472a6753af9d0998ab6f5f6647fea4..2de79e2df0af6a7e79a93a39c154b27bf2977d1f 100644 (file)
@@ -313,7 +313,7 @@ def test_compatible_classes_in_global_and_localedata(filename):
                                          (module, name))
 
     with open(filename, 'rb') as f:
-        return Unpickler(f).load()
+        assert Unpickler(f).load()
 
 
 def test_issue_601_no_language_name_but_has_variant():
diff --git a/tox.ini b/tox.ini
index dd0ee6703f09d4621ce3a849dc0c7d6c791f30a9..97b6bc09ceaabbea6cad9bd46f9083283ca5458b 100644 (file)
--- a/tox.ini
+++ b/tox.ini
@@ -5,7 +5,7 @@ envlist =
 
 [testenv]
 deps =
-    pytest
+    pytest>=6.0
     pytest-cov
     freezegun==0.3.12
     backports.zoneinfo;python_version<"3.9"