MCPcopy
hub / github.com/psycopg/psycopg / test_connection_warn_close

Function test_connection_warn_close

tests/test_connection.py:219–251  ·  tests/test_connection.py::test_connection_warn_close
(conn_cls, dsn, recwarn, gc_collect)

Source from the content-addressed store, hash-verified

217
218@pytest.mark.slow
219def test_connection_warn_close(conn_cls, dsn, recwarn, gc_collect):
220 class="cm"># First create all the connections to test, to avoid some to reuse the same
221 class="cm"># address, resulting in an omitted warning.
222 conn1 = conn_cls.connect(dsn)
223 conn2 = conn_cls.connect(dsn)
224 conn3 = conn_cls.connect(dsn)
225 conn4 = conn_cls.connect(dsn)
226
227 with conn_cls.connect(dsn) as conn5:
228 pass
229 del conn5
230 assert not recwarn, [str(w.message) for w in recwarn.list]
231
232 conn1.close()
233 del conn1
234 assert not recwarn, [str(w.message) for w in recwarn.list]
235
236 del conn2
237 gc_collect()
238 assert conn_cls.__name__ in str(recwarn.pop(ResourceWarning).message)
239
240 conn3.execute(class="st">"select 1")
241 del conn3
242 gc_collect()
243 assert conn_cls.__name__ in str(recwarn.pop(ResourceWarning).message)
244
245 try:
246 conn4.execute(class="st">"select wat")
247 except psycopg.ProgrammingError:
248 pass
249 del conn4
250 gc_collect()
251 assert conn_cls.__name__ in str(recwarn.pop(ResourceWarning).message)
252
253
254@pytest.mark.usefixtures(class="st">"testctx")

Callers

nothing calls this directly

Calls 4

gc_collectFunction · 0.85
connectMethod · 0.45
closeMethod · 0.45
executeMethod · 0.45

Tested by

no test coverage detected