|
2 | 2 | Collection of test cases to test connection module. |
3 | 3 | """ |
4 | 4 |
|
5 | | -from nose.tools import assert_true, assert_false, raises |
| 5 | +import pytest |
6 | 6 | import datajoint as dj |
7 | 7 | from datajoint import DataJointError |
8 | 8 | from . import CONN_INFO |
9 | 9 |
|
10 | 10 |
|
| 11 | +@pytest.fixture |
| 12 | +def conn(connection_root): |
| 13 | + return dj.conn(reset=True, **CONN_INFO) |
| 14 | + |
| 15 | + |
11 | 16 | class TestReconnect: |
12 | 17 | """ |
13 | | - test reconnection |
| 18 | + Test reconnection |
14 | 19 | """ |
15 | 20 |
|
16 | | - def setup(self): |
17 | | - self.conn = dj.conn(reset=True, **CONN_INFO) |
18 | | - |
19 | | - def test_close(self): |
20 | | - assert self.conn.is_connected, "Connection should be alive" |
21 | | - self.conn.close() |
22 | | - assert not self.conn.is_connected, "Connection should now be closed" |
23 | | - |
24 | | - def test_reconnect(self): |
25 | | - assert self.conn.is_connected, "Connection should be alive" |
26 | | - self.conn.close() |
27 | | - self.conn.query("SHOW DATABASES;", reconnect=True).fetchall() |
28 | | - assert self.conn.is_connected, "Connection should be alive" |
29 | | - |
30 | | - @raises(DataJointError) |
31 | | - def test_reconnect_throws_error_in_transaction(self): |
32 | | - assert self.conn.is_connected, "Connection should be alive" |
33 | | - with self.conn.transaction: |
34 | | - self.conn.close() |
35 | | - self.conn.query("SHOW DATABASES;", reconnect=True).fetchall() |
| 21 | + def test_close(self, conn): |
| 22 | + assert conn.is_connected, "Connection should be alive" |
| 23 | + conn.close() |
| 24 | + assert not conn.is_connected, "Connection should now be closed" |
| 25 | + |
| 26 | + def test_reconnect(self, conn): |
| 27 | + assert conn.is_connected, "Connection should be alive" |
| 28 | + conn.close() |
| 29 | + conn.query("SHOW DATABASES;", reconnect=True).fetchall() |
| 30 | + assert conn.is_connected, "Connection should be alive" |
| 31 | + |
| 32 | + def test_reconnect_throws_error_in_transaction(self, conn): |
| 33 | + assert conn.is_connected, "Connection should be alive" |
| 34 | + with conn.transaction, pytest.raises(DataJointError): |
| 35 | + conn.close() |
| 36 | + conn.query("SHOW DATABASES;", reconnect=True).fetchall() |
0 commit comments