`test_environment_does_not_update_on_past_event` is flaky

未关闭
#187 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
50/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
停滞
技术栈
python
领域
testing

调研方向

从 tests/test_streaming_manager.py 开始,并在 Python 3.10 下运行 test_environment_does_not_update_on_past_event,以复现间歇性失败。检查 Flagsmith.handle_stream_event 和模拟的 update_environment 调用;当过去的 StreamEvent 不调用 update_environment 且 streaming manager 测试能够稳定通过时,即表示完成。

由索引模型根据 Issue 内容生成。

描述

The following test is failing sometimes for Python 3.10:

============================= test session starts ==============================
platform linux -- Python 3.10.19, pytest-7.4.4, pluggy-1.5.0
rootdir: /home/runner/work/flagsmith-python-client/flagsmith-python-client
plugins: mock-3.14.1, cov-4.1.0, pyfakefs-5.9.2
collected 73 items

tests/test_analytics.py .....                                            [  6%]
tests/test_flagsmith.py ...........................................      [ 65%]
tests/test_models.py ............                                        [ 82%]
tests/test_offline_handlers.py ..                                        [ 84%]
tests/test_polling_manager.py ....                                       [ 90%]
tests/test_streaming_manager.py ..F.                                     [ 95%]
tests/test_webhooks.py ...                                               [100%]

=================================== FAILURES ===================================
________________ test_environment_does_not_update_on_past_event ________________

self = <MagicMock name='update_environment' id='140607846335680'>

    def assert_not_called(self):
        """assert that the mock was never called.
        """
        if self.call_count != 0:
            msg = ("Expected '%s' to not have been called. Called %s times.%s"
                   % (self._mock_name or 'mock',
                      self.call_count,
                      self._calls_repr()))
>           raise AssertionError(msg)
E           AssertionError: Expected 'update_environment' to not have been called. Called 2 times.
E           Calls: [call(), call()].

/opt/hostedtoolcache/Python/3.10.19/x64/lib/python3.10/unittest/mock.py:890: AssertionError

During handling of the above exception, another exception occurred:

server_api_key = 'ser.ZnjtUuLXOhrkpIQbVTJR'
mocker = <pytest_mock.plugin.MockerFixture object at 0x7fe1d0bbc340>

    def test_environment_does_not_update_on_past_event(
        server_api_key: str, mocker: MockerFixture
    ) -> None:
        stream_updated_at = datetime(2020, 1, 1, 1, 1, 1, tzinfo=timezone.utc)
        environment_updated_at = datetime(2020, 1, 1, 1, 1, 2, tzinfo=timezone.utc)
    
        mocker.patch("flagsmith.Flagsmith.update_environment")
    
        flagsmith = Flagsmith(environment_key=server_api_key)
        flagsmith._evaluation_context = MagicMock()
        flagsmith._environment_updated_at = environment_updated_at
    
        flagsmith.handle_stream_event(event=StreamEvent(updated_at=stream_updated_at))
        assert isinstance(flagsmith.update_environment, Mock)
>       flagsmith.update_environment.assert_not_called()
E       AssertionError: Expected 'update_environment' to not have been called. Called 2 times.
E       Calls: [call(), call()].

tests/test_streaming_manager.py:68: AssertionError
=========================== short test summary info ============================
FAILED tests/test_streaming_manager.py::test_environment_does_not_update_on_past_event - AssertionError: Expected 'update_environment' to not have been called. Called 2 times.
Calls: [call(), call()].
========================= 1 failed, 72 passed in 0.80s =========================
主要语言
Python
星标
24
派生
12
平均合并
15 小时 43 分钟
30 天内合并 PR
4

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

Flagsmith/flagsmith-python-client 的其他 Issue

查看 Flagsmith/flagsmith-python-client 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。