Skip to content

Commit e3672f6

Browse files
committed
Migrate test_reconnection
1 parent f3a5dd1 commit e3672f6

File tree

1 file changed

+23
-22
lines changed

1 file changed

+23
-22
lines changed

tests/test_reconnection.py

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,35 @@
22
Collection of test cases to test connection module.
33
"""
44

5-
from nose.tools import assert_true, assert_false, raises
5+
import pytest
66
import datajoint as dj
77
from datajoint import DataJointError
88
from . import CONN_INFO
99

1010

11+
@pytest.fixture
12+
def conn(connection_root):
13+
return dj.conn(reset=True, **CONN_INFO)
14+
15+
1116
class TestReconnect:
1217
"""
13-
test reconnection
18+
Test reconnection
1419
"""
1520

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

Comments
 (0)