[New-bugs-announce] [issue41785] Unittest do not support datatime for AlmostEqual method

Hildo Guillardi Júnior report at bugs.python.org
Mon Sep 14 16:57:09 EDT 2020


New submission from Hildo Guillardi Júnior <hildogjr at gmail.com>:

I am running a test

`self.assertAlmostEqual(date1, date2, 6)`

and getting the result:

ERROR: test_datetime_linspace (__main__.TestFunctions)
Check the linspace object output type and delta between them.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/lab/Documents/UNICAMP/LabREI/web-visualization/tests/test_interpreter.py", line 87, in test_datetime_linspace
    self.assertAlmostEqual(time_list[-1], now, 6)
  File "/usr/lib/python3.8/unittest/case.py", line 957, in assertAlmostEqual
    if round(diff, places) == 0:
TypeError: type datetime.timedelta doesn't define __round__ method


Despite the definition

@overload
    def assertAlmostEqual(self, first: datetime.datetime, second: datetime.datetime,
                          places: int = ..., msg: Any = ...,
                          delta: datetime.timedelta = ...) -> None: ...

on file case.pyi, the case.py doesn't deal good with `if round(diff, places) == 0:`, with `diff` the difference between the two varaibles.

----------
components: 2to3 (2.x to 3.x conversion tool)
messages: 376904
nosy: hildogjr
priority: normal
severity: normal
status: open
title: Unittest do not support datatime for AlmostEqual method
type: behavior
versions: Python 3.8

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue41785>
_______________________________________


More information about the New-bugs-announce mailing list