AndreyErmilov / pytest-mock-server

Mock server plugin for pytest
MIT License
27 stars 5 forks source link

time.sleep to wait server ready #5

Open BrightXiaoHan opened 2 years ago

BrightXiaoHan commented 2 years ago
    @pytest.mark.server(url=f'/termprojsbypage/{moke_terms_db_id}', response=fake_terms_db_1, method='GET')
    @pytest.mark.server_settings(port=free_port)
    def test_word_level_mask(self):
        import time
        time.sleep(2)
        config = {
            "term_mask_url": f"http://127.0.0.1:{self.free_port}",
            "translate_src_lang": "en",
        }
        protector = CodeSwitchProtector(config)
        for case in self._word_level_test_cases:
            sent, terms = protector.mask(case.text, self.moke_terms_db_id)
            assert sent == case.masked
            assert terms == case.terms

This is my code, I found that I must take a break to wait for the server ready.

BrightXiaoHan commented 2 years ago

or it will raise ConnectionError when I make a request to the server

raise ConnectionError(e, request=request)
E           requests.exceptions.ConnectionError: HTTPConnectionPool(host='127.0.0.1', port=39218): Max retries exceeded with url: /termprojsbypage/test_terms_db_id?CurrentPage=1&PageSize=1000000&sort=Origin.desc&RowKey=&Modifier=&rText=&tText=&Remark= (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7fb33ca00100>: Failed to establish a new connection: [Errno 111] Connection refused'))