freezegun
freezegun copied to clipboard
Timezone America/Sao_Paulo triggers recursion errors in tests.
Whilst I was looking into https://bugs.gentoo.org/877603 (which ended up being the previously reported https://github.com/spulec/freezegun/issues/513) I tried to test TZ="America/Sao_Paulo" which failed quite horribly with recursion errors.
$ TZ="America/Sao_Paulo" tox -e py311
.pkg: _optional_hooks> python /usr/lib/python3.12/site-packages/pyproject_api/_backend.py True setuptools.build_meta
.pkg: get_requires_for_build_sdist> python /usr/lib/python3.12/site-packages/pyproject_api/_backend.py True setuptools.build_meta
.pkg: get_requires_for_build_wheel> python /usr/lib/python3.12/site-packages/pyproject_api/_backend.py True setuptools.build_meta
.pkg: prepare_metadata_for_build_wheel> python /usr/lib/python3.12/site-packages/pyproject_api/_backend.py True setuptools.build_meta
.pkg: build_sdist> python /usr/lib/python3.12/site-packages/pyproject_api/_backend.py True setuptools.build_meta
py311: install_package> python -I -m pip install --force-reinstall --no-deps /home/ask/sources/freezegun/.tox/.tmp/package/15/freezegun-1.2.2.tar.gz
py311: commands[0]> pytest --cov
========================================================================================================= test session starts ==========================================================================================================
platform linux -- Python 3.11.6, pytest-7.4.3, pluggy-1.3.0
cachedir: .tox/py311/.pytest_cache
rootdir: /home/ask/sources/freezegun
plugins: cov-4.1.0
collected 127 items
tests/test_asyncio.py ..... [ 3%]
tests/test_class_import.py ..F........... [ 14%]
tests/test_configure.py .. [ 16%]
tests/test_datetimes.py FF.F.............sF....s.......s...........FF...FFF.........F......F..s [ 72%]
tests/test_errors.py FF [ 74%]
tests/test_import_alias.py ... [ 76%]
tests/test_operations.py ......... [ 83%]
tests/test_pickle.py ... [ 85%]
tests/test_sqlite3.py .. [ 87%]
tests/test_ticking.py .s........ [ 95%]
tests/test_utils.py
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR> File "/home/ask/sources/freezegun/.tox/py311/lib/python3.11/site-packages/coverage/sqldata.py", line 1106, in execute
INTERNALERROR> return self.con.execute(sql, parameters)
INTERNALERROR> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR> sqlite3.OperationalError: no such table: coverage_schema
INTERNALERROR>
INTERNALERROR> During handling of the above exception, another exception occurred:
INTERNALERROR>
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR> File "/home/ask/sources/freezegun/.tox/py311/lib/python3.11/site-packages/coverage/sqldata.py", line 1111, in execute
INTERNALERROR> return self.con.execute(sql, parameters)
INTERNALERROR> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR> sqlite3.OperationalError: no such table: coverage_schema
INTERNALERROR>
INTERNALERROR> The above exception was the direct cause of the following exception:
INTERNALERROR>
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR> File "/home/ask/sources/freezegun/.tox/py311/lib/python3.11/site-packages/coverage/sqldata.py", line 272, in _read_db
INTERNALERROR> schema_version, = db.execute_one("select version from coverage_schema")
INTERNALERROR> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR> File "/home/ask/sources/freezegun/.tox/py311/lib/python3.11/site-packages/coverage/sqldata.py", line 1147, in execute_one
INTERNALERROR> rows = list(self.execute(sql, parameters))
INTERNALERROR> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR> File "/home/ask/sources/freezegun/.tox/py311/lib/python3.11/site-packages/coverage/sqldata.py", line 1128, in execute
INTERNALERROR> raise DataError(f"Couldn't use data file {self.filename!r}: {msg}") from exc
INTERNALERROR> coverage.exceptions.DataError: Couldn't use data file '/home/ask/sources/freezegun/.coverage.bigglane.13778.177439': no such table: coverage_schema
INTERNALERROR>
INTERNALERROR> During handling of the above exception, another exception occurred:
INTERNALERROR>
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR> File "/home/ask/sources/freezegun/.tox/py311/lib/python3.11/site-packages/_pytest/main.py", line 271, in wrap_session
INTERNALERROR> session.exitstatus = doit(config, session) or 0
INTERNALERROR> ^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR> File "/home/ask/sources/freezegun/.tox/py311/lib/python3.11/site-packages/_pytest/main.py", line 325, in _main
INTERNALERROR> config.hook.pytest_runtestloop(session=session)
INTERNALERROR> File "/home/ask/sources/freezegun/.tox/py311/lib/python3.11/site-packages/pluggy/_hooks.py", line 493, in __call__
INTERNALERROR> return self._hookexec(self.name, self._hookimpls, kwargs, firstresult)
INTERNALERROR> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR> File "/home/ask/sources/freezegun/.tox/py311/lib/python3.11/site-packages/pluggy/_manager.py", line 115, in _hookexec
INTERNALERROR> return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
INTERNALERROR> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR> File "/home/ask/sources/freezegun/.tox/py311/lib/python3.11/site-packages/pluggy/_callers.py", line 130, in _multicall
INTERNALERROR> teardown[0].send(outcome)
INTERNALERROR> File "/home/ask/sources/freezegun/.tox/py311/lib/python3.11/site-packages/pytest_cov/plugin.py", line 298, in pytest_runtestloop
INTERNALERROR> self.cov_controller.finish()
INTERNALERROR> File "/home/ask/sources/freezegun/.tox/py311/lib/python3.11/site-packages/pytest_cov/engine.py", line 44, in ensure_topdir_wrapper
INTERNALERROR> return meth(self, *args, **kwargs)
INTERNALERROR> ^^^^^^^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR> File "/home/ask/sources/freezegun/.tox/py311/lib/python3.11/site-packages/pytest_cov/engine.py", line 250, in finish
INTERNALERROR> self.cov.save()
INTERNALERROR> File "/home/ask/sources/freezegun/.tox/py311/lib/python3.11/site-packages/coverage/control.py", line 710, in save
INTERNALERROR> data = self.get_data()
INTERNALERROR> ^^^^^^^^^^^^^^^
INTERNALERROR> File "/home/ask/sources/freezegun/.tox/py311/lib/python3.11/site-packages/coverage/control.py", line 782, in get_data
INTERNALERROR> if self._collector and self._collector.flush_data():
INTERNALERROR> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR> File "/home/ask/sources/freezegun/.tox/py311/lib/python3.11/site-packages/coverage/collector.py", line 475, in flush_data
INTERNALERROR> self.covdata.add_lines(self.mapped_file_dict(self.data))
INTERNALERROR> File "/home/ask/sources/freezegun/.tox/py311/lib/python3.11/site-packages/coverage/sqldata.py", line 238, in _wrapped
INTERNALERROR> return method(self, *args, **kwargs)
INTERNALERROR> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR> File "/home/ask/sources/freezegun/.tox/py311/lib/python3.11/site-packages/coverage/sqldata.py", line 465, in add_lines
INTERNALERROR> self._choose_lines_or_arcs(lines=True)
INTERNALERROR> File "/home/ask/sources/freezegun/.tox/py311/lib/python3.11/site-packages/coverage/sqldata.py", line 528, in _choose_lines_or_arcs
INTERNALERROR> with self._connect() as con:
INTERNALERROR> ^^^^^^^^^^^^^^^
INTERNALERROR> File "/home/ask/sources/freezegun/.tox/py311/lib/python3.11/site-packages/coverage/sqldata.py", line 315, in _connect
INTERNALERROR> self._open_db()
INTERNALERROR> File "/home/ask/sources/freezegun/.tox/py311/lib/python3.11/site-packages/coverage/sqldata.py", line 266, in _open_db
INTERNALERROR> self._read_db()
INTERNALERROR> File "/home/ask/sources/freezegun/.tox/py311/lib/python3.11/site-packages/coverage/sqldata.py", line 275, in _read_db
INTERNALERROR> self._init_db(db)
INTERNALERROR> File "/home/ask/sources/freezegun/.tox/py311/lib/python3.11/site-packages/coverage/sqldata.py", line 308, in _init_db
INTERNALERROR> ("when", datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")),
INTERNALERROR> ^^^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR> File "/home/ask/sources/freezegun/freezegun/api.py", line 387, in now
INTERNALERROR> now = cls._time_to_freeze() or real_datetime.now()
INTERNALERROR> ^^^^^^^^^^^^^^^^^^^
INTERNALERROR> File "/home/ask/sources/freezegun/freezegun/api.py", line 387, in now
INTERNALERROR> now = cls._time_to_freeze() or real_datetime.now()
INTERNALERROR> ^^^^^^^^^^^^^^^^^^^
INTERNALERROR> File "/home/ask/sources/freezegun/freezegun/api.py", line 387, in now
INTERNALERROR> now = cls._time_to_freeze() or real_datetime.now()
INTERNALERROR> ^^^^^^^^^^^^^^^^^^^
INTERNALERROR> [Previous line repeated 969 more times]
INTERNALERROR> RecursionError: maximum recursion depth exceeded
Traceback (most recent call last):
File "/home/ask/sources/freezegun/.tox/py311/bin/pytest", line 8, in <module>
sys.exit(console_main())
^^^^^^^^^^^^^^
File "/home/ask/sources/freezegun/.tox/py311/lib/python3.11/site-packages/_pytest/config/__init__.py", line 192, in console_main
code = main()
^^^^^^
File "/home/ask/sources/freezegun/.tox/py311/lib/python3.11/site-packages/_pytest/config/__init__.py", line 169, in main
ret: Union[ExitCode, int] = config.hook.pytest_cmdline_main(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/ask/sources/freezegun/.tox/py311/lib/python3.11/site-packages/pluggy/_hooks.py", line 493, in __call__
return self._hookexec(self.name, self._hookimpls, kwargs, firstresult)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/ask/sources/freezegun/.tox/py311/lib/python3.11/site-packages/pluggy/_manager.py", line 115, in _hookexec
return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/ask/sources/freezegun/.tox/py311/lib/python3.11/site-packages/pluggy/_callers.py", line 113, in _multicall
raise exception.with_traceback(exception.__traceback__)
File "/home/ask/sources/freezegun/.tox/py311/lib/python3.11/site-packages/pluggy/_callers.py", line 77, in _multicall
res = hook_impl.function(*args)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/ask/sources/freezegun/.tox/py311/lib/python3.11/site-packages/_pytest/main.py", line 318, in pytest_cmdline_main
return wrap_session(config, _main)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/ask/sources/freezegun/.tox/py311/lib/python3.11/site-packages/_pytest/main.py", line 306, in wrap_session
config.hook.pytest_sessionfinish(
File "/home/ask/sources/freezegun/.tox/py311/lib/python3.11/site-packages/pluggy/_hooks.py", line 493, in __call__
return self._hookexec(self.name, self._hookimpls, kwargs, firstresult)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/ask/sources/freezegun/.tox/py311/lib/python3.11/site-packages/pluggy/_manager.py", line 115, in _hookexec
return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/ask/sources/freezegun/.tox/py311/lib/python3.11/site-packages/pluggy/_callers.py", line 130, in _multicall
teardown[0].send(outcome)
File "/home/ask/sources/freezegun/.tox/py311/lib/python3.11/site-packages/_pytest/terminal.py", line 877, in pytest_sessionfinish
self.summary_stats()
File "/home/ask/sources/freezegun/.tox/py311/lib/python3.11/site-packages/_pytest/terminal.py", line 1099, in summary_stats
session_duration = timing.time() - self._sessionstarttime
^^^^^^^^^^^^^
File "/home/ask/sources/freezegun/freezegun/api.py", line 176, in fake_time
return real_time()
^^^^^^^^^^^
File "/home/ask/sources/freezegun/freezegun/api.py", line 176, in fake_time
return real_time()
^^^^^^^^^^^
File "/home/ask/sources/freezegun/freezegun/api.py", line 176, in fake_time
return real_time()
^^^^^^^^^^^
[Previous line repeated 980 more times]
File "/home/ask/sources/freezegun/freezegun/api.py", line 175, in fake_time
if _should_use_real_time():
^^^^^^^^^^^^^^^^^^^^^^^
RecursionError: maximum recursion depth exceeded
py311: exit 1 (1.51 seconds) /home/ask/sources/freezegun> pytest --cov pid=13778
.pkg: _exit> python /usr/lib/python3.12/site-packages/pyproject_api/_backend.py True setuptools.build_meta
py311: FAIL code 1 (4.20=setup[2.68]+cmd[1.51] seconds)
evaluation failed :( (4.31 seconds)
Below are modification to tox.ini to pass the TZ so it can be reproduced with tox.
diff --git a/tox.ini b/tox.ini
index 96a5703..141dc3a 100644
--- a/tox.ini
+++ b/tox.ini
@@ -9,6 +9,7 @@ envlist = py37, py38, py39, py310, py311, pypy3, mypy
[testenv]
commands = pytest --cov {posargs}
deps = -rrequirements.txt
+passenv = TZ
[testenv:mypy]
deps =
Can I work on this issue?
@SarthakNikhal You don't need permission to work on issues if you feel so inclined. Currently just don't think changes would be merged.
https://github.com/spulec/freezegun/pull/511#issuecomment-1748219731
So it may be wasted effort to fix this, unless you are doing it to learn of course.
@SarthakNikhal @parona-source There are maintainers around now, so PR's are welcome.