Closed dvzrv closed 3 years ago
So then pytest, as usual, does something incomprehensible, which is the reason I don't use it. Thanks for the heads up, I'll look into this next time I get time.
I am facing the same issue while running pytest on tzlocal.
test_assert_tz_offset (tests.tests.TzLocalTests) ... /usr/src/photon/BUILD/tzlocal-2.1/tzlocal/unix.py:158: UserWarning: Can not find any timezone configuration, defaulting to UTC.
warnings.warn('Can not find any timezone configuration, defaulting to UTC.')
ok
test_env (tests.tests.TzLocalTests) ... ok
test_fail (tests.tests.TzLocalTests) ... FAIL
test_get_reload (tests.tests.TzLocalTests) ... ok
test_only_localtime (tests.tests.TzLocalTests) ... ok
test_symlink_localtime (tests.tests.TzLocalTests) ... ok
test_timezone (tests.tests.TzLocalTests) ... ok
test_timezone_setting (tests.tests.TzLocalTests) ... ok
test_timezone_top_line_comment (tests.tests.TzLocalTests) ... ok
test_vardbzoneinfo_setting (tests.tests.TzLocalTests) ... ok
test_zone_setting (tests.tests.TzLocalTests) ... ok
test_win32_on_unix (tests.tests.TzWin32Tests) ... ok
======================================================================
FAIL: test_fail (tests.tests.TzLocalTests)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/usr/src/photon/BUILD/tzlocal-2.1/tests/tests.py", line 116, in test_fail
self.assertIn('Can not find any timezone configuration',
AssertionError: 'Can not find any timezone configuration' not found in ''
----------------------------------------------------------------------
Ran 12 tests in 0.026s
FAILED (failures=1)
Test failed: <unittest.runner.TextTestResult run=12 errors=0 failures=1>
error: Test failed: <unittest.runner.TextTestResult run=12 errors=0 failures=1>
This issue has to do with pytest
's warnings capture. You can use -p no:warnings
and the test will start working again.
If tzlocal
adopts pytest
, there's a much easier way to write this test using [pytest.warns](https://docs.pytest.org/en/3.0.2/recwarn.html)
. I've also written a custom assertWarns
context manager that, IIRC, was compatible with pytest
as well. (Though obviously if this project doesn't support the use of pytest
as a test runner, then people should use python -m unittest discover
or whatever the proper invocation is).
I've done this in https://github.com/regebro/tzlocal/pull/94.
Hi! I'm packaging python-tzlocal for Arch Linux. When building version 2.1 I ran pytest against the build (
pytest -v tests/tests.py
), but it fails on one test:I have tried exporting TZ for a valid timezone before the pytest call, but it doesn't get picked up. I'm a little clueless as to why this doesn't work tbh. The
python setup.py test
call works, but will soon be obsoleted, which is why I'd rather run pytest.Any insights would be highly appreciated!