File tree Expand file tree Collapse file tree 4 files changed +47
-7
lines changed Expand file tree Collapse file tree 4 files changed +47
-7
lines changed Original file line number Diff line number Diff line change
1
+ import psycopg2
2
+
3
+
4
+ class MyDB :
5
+ def __init__ (self ):
6
+ self .conn = None
7
+
8
+ def __enter__ (self ):
9
+ self .conn = psycopg2 .connect ("host=localhost dbname=test user=postgres "
10
+ "password=docker" )
11
+ self .conn .autocommit = True
12
+
13
+ def __exit__ (self , * args ):
14
+ if self .conn :
15
+ self .conn .close ()
16
+ self .conn = None
Load Diff This file was deleted.
Load Diff This file was deleted.
Original file line number Diff line number Diff line change
1
+ from db_object import MyDB
2
+ import psycopg2
3
+
4
+ import pytest
5
+
6
+
7
+ @pytest .fixture (scope = 'module' )
8
+ def cur ():
9
+ print ("creating connection" )
10
+ db = MyDB ()
11
+ db .conn = psycopg2 .connect ("host=localhost dbname=test user=postgres "
12
+ "password=docker" )
13
+ cur = db .conn .cursor ()
14
+ yield cur
15
+ cur .close ()
16
+ db .conn .close ()
17
+ print ("closing db" )
18
+
19
+
20
+ def test_table_count (cur ):
21
+ cur .execute ("SELECT COUNT(*) FROM test_table" )
22
+ result = cur .fetchone ()
23
+
24
+ assert int (result [0 ]) == 1
25
+
26
+
27
+ def test_table_value (cur ):
28
+ cur .execute ("SELECT * FROM test_table" )
29
+ result = cur .fetchone ()
30
+
31
+ assert result == (1 , 'a' )
You can’t perform that action at this time.
0 commit comments