datetime.strptime 失败 CI
datetime.strptime failure in CI
我有以下错误只发生在 CI:
ValueError: time data '09.30.2019 17:50 EDT' does not match format '%m.%d.%Y %H:%M %Z'
这是我的测试:
def test_extract_time_from_page(pjm_html):
expected_time = datetime.strptime("09.30.2019 17:50 EDT", "%m.%d.%Y %H:%M %Z")
res = demand.extract_time_from_page(pjm_html)
assert res == expected_time
本地通过。我不确定在 CI 环境
中这会有什么不同 运行
编辑:我可以通过将我的机器时区更改为美国东部时间以外的时区来重现这一点。您不能使用与 datetime.strptime
当前时区不同的时区吗?
可能是 pytz 库的问题。比较 CI worker 和本地的 pytz 库。 Here you can find an explanation which points to wikipedia list of timezones 表示 EDT 是一个已弃用的时区。您可以尝试在 CI worker.
上更新您的 pytz 库
这是对文档进行修订的known issue with the %Z
directive. The current documentation is confusing and there is a pending request。待定文档更改解释了您遇到的问题:
Note that strptime
only accepts certain values for %Z
: UTC
and GMT
, and what is defined in time.tzname
for your own
locales. It will return a ValueError
for any invalid strings. For
example, someone living in Japan will have UTC
, GMT
and
JST
as valid values, but probably not EST
.
我有以下错误只发生在 CI:
ValueError: time data '09.30.2019 17:50 EDT' does not match format '%m.%d.%Y %H:%M %Z'
这是我的测试:
def test_extract_time_from_page(pjm_html):
expected_time = datetime.strptime("09.30.2019 17:50 EDT", "%m.%d.%Y %H:%M %Z")
res = demand.extract_time_from_page(pjm_html)
assert res == expected_time
本地通过。我不确定在 CI 环境
中这会有什么不同 运行编辑:我可以通过将我的机器时区更改为美国东部时间以外的时区来重现这一点。您不能使用与 datetime.strptime
当前时区不同的时区吗?
可能是 pytz 库的问题。比较 CI worker 和本地的 pytz 库。 Here you can find an explanation which points to wikipedia list of timezones 表示 EDT 是一个已弃用的时区。您可以尝试在 CI worker.
上更新您的 pytz 库这是对文档进行修订的known issue with the %Z
directive. The current documentation is confusing and there is a pending request。待定文档更改解释了您遇到的问题:
Note that
strptime
only accepts certain values for%Z
:UTC
andGMT
, and what is defined intime.tzname
for your own locales. It will return aValueError
for any invalid strings. For example, someone living in Japan will haveUTC
,GMT
andJST
as valid values, but probably notEST
.