Skip to content

pytest fails with python 3.12b4 possibly due to Fraction formatting change #1818

@mtasaka

Description

@mtasaka

With python 3.12b4 (actually on Fedora 39, python3-3.12.0~b4-1.fc39.x86_64), pytest for pint git head ( 2d649ea ) fails as below:

$ pytest --benchmark-skip
============================= test session starts ==============================
platform linux -- Python 3.12.0b4, pytest-7.3.2, pluggy-1.0.0
benchmark: 4.0.0 (defaults: timer=time.perf_counter disable_gc=False min_rounds=5 min_time=0.000005 max_time=1.0 calibration_precision=10 warmup=False warmup_iterations=100000)
Matplotlib: 3.7.2
Freetype: 2.13.1
rootdir: /builddir/build/BUILD/GIT/pint
plugins: cov-4.0.0, benchmark-4.0.0, subtests-0.10.0, mpl-0.13
collected 2536 items / 3 skipped
....
....
-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
=========================== short test summary info ============================
FAILED pint/testsuite/test_non_int.py::TestNonIntTypeQuantityFraction::test_to_base_units
FAILED pint/testsuite/test_non_int.py::TestNonIntTypeOffsetUnitMathFraction::test_multiplication[input_tuple0-expected_output0]
FAILED pint/testsuite/test_non_int.py::TestNonIntTypeOffsetUnitMathFraction::test_multiplication[input_tuple21-expected_output21]
FAILED pint/testsuite/test_non_int.py::TestNonIntTypeOffsetUnitMathFraction::test_multiplication[input_tuple28-expected_output28]
FAILED pint/testsuite/test_non_int.py::TestNonIntTypeOffsetUnitMathFraction::test_multiplication[input_tuple35-expected_output35]
FAILED pint/testsuite/test_non_int.py::TestNonIntTypeOffsetUnitMathFraction::test_multiplication_with_autoconvert[input_tuple0-expected_output0]
FAILED pint/testsuite/test_non_int.py::TestNonIntTypeOffsetUnitMathFraction::test_multiplication_with_autoconvert[input_tuple1-expected_output1]
FAILED pint/testsuite/test_non_int.py::TestNonIntTypeOffsetUnitMathFraction::test_multiplication_with_autoconvert[input_tuple2-expected_output2]
FAILED pint/testsuite/test_non_int.py::TestNonIntTypeOffsetUnitMathFraction::test_multiplication_with_autoconvert[input_tuple3-expected_output3]
FAILED pint/testsuite/test_non_int.py::TestNonIntTypeOffsetUnitMathFraction::test_multiplication_with_autoconvert[input_tuple4-expected_output4]
FAILED pint/testsuite/test_non_int.py::TestNonIntTypeOffsetUnitMathFraction::test_multiplication_with_autoconvert[input_tuple8-expected_output8]
FAILED pint/testsuite/test_non_int.py::TestNonIntTypeOffsetUnitMathFraction::test_multiplication_with_autoconvert[input_tuple9-expected_output9]
FAILED pint/testsuite/test_non_int.py::TestNonIntTypeOffsetUnitMathFraction::test_multiplication_with_autoconvert[input_tuple10-expected_output10]
FAILED pint/testsuite/test_non_int.py::TestNonIntTypeOffsetUnitMathFraction::test_multiplication_with_scalar[input_tuple1-expected_output1]
FAILED pint/testsuite/test_non_int.py::TestNonIntTypeOffsetUnitMathFraction::test_division_with_scalar[input_tuple1-expected_output1]
FAILED pint/testsuite/test_non_int.py::TestNonIntTypeOffsetUnitMathFraction::test_exponentiation[input_tuple3-expected_output3]
= 16 failed, 2009 passed, 503 skipped, 11 xfailed, 6 warnings, 298 subtests passed in 182.14s (0:03:02) =

... and all of the above failures are like:

______________ TestNonIntTypeQuantityFraction.test_to_base_units _______________
self = <pint.testsuite.test_non_int.TestNonIntTypeQuantityFraction object at 0x7f1635287b00>

    def test_to_base_units(self):
        x = self.Q_("1*inch")
        self.assert_quantity_almost_equal(
            x.to_base_units(), self.QP_("0.0254", "meter")
        )
        x = self.Q_("1*inch*inch")
>       self.assert_quantity_almost_equal(
            x.to_base_units(),
            self.Q_(
                self.kwargs["non_int_type"]("0.0254")
                ** self.kwargs["non_int_type"]("2.0"),
                "meter*meter",
            ),
        )

pint/testsuite/test_non_int.py:159: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
pint/testsuite/test_non_int.py:29: in assert_quantity_almost_equal
    helpers.assert_quantity_almost_equal(
pint/testing.py:66: in assert_allclose
    msg = f"Comparing {first!r} and {second!r}. "
pint/facets/plain/quantity.py:262: in __repr__
    return f"<Quantity({self._magnitude}, '{self._units}')>"
pint/util.py:608: in __format__
    return format_unit(self, spec)
pint/formatting.py:452: in format_unit
    return fmt(unit, registry=registry, **options)
pint/formatting.py:268: in format_default
    return formatter(
pint/formatting.py:386: in formatter
    pos_terms.append(power_fmt.format(key, fun(value)))
pint/formatting.py:349: in <lambda>
    fun = lambda x: exp_call(abs(x))
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = Fraction(2, 1), format_spec = 'n'

    def __format__(self, format_spec, /):
        """Format this fraction according to the given format specification."""
    
        # Backwards compatiblility with existing formatting.
        if not format_spec:
            return str(self)
    
        # Validate and parse the format specifier.
        match = _FLOAT_FORMAT_SPECIFICATION_MATCHER(format_spec)
        if match is None:
>           raise ValueError(
                f"Invalid format specifier {format_spec!r} "
                f"for object of type {type(self).__name__!r}"
E               ValueError: Invalid format specifier 'n' for object of type 'Fraction'

/usr/lib64/python3.12/fractions.py:427: ValueError

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions