File tree Expand file tree Collapse file tree 7 files changed +97
-16
lines changed
Expand file tree Collapse file tree 7 files changed +97
-16
lines changed Original file line number Diff line number Diff line change @@ -24,19 +24,3 @@ def _temp_file():
2424 print ('the current temp path is {}' .format (temp ))
2525 yield temp
2626 os .remove (temp )
27-
28-
29- @pytest .fixture ()
30- def cleandir ():
31- ''' cleandir '''
32- newpath = tempfile .mkdtemp ()
33- os .chdir (newpath )
34- print ('\n the current temp dir is {}' .format (newpath ))
35-
36-
37- # @pytest.mark.xfail(raises=ZeroDivisionError)
38- # def test_zero_division():
39- # ''' test zero division'''
40- # 1/0
41- # with pytest.raises(ZeroDivisionError):
42- # 1 / 0
Original file line number Diff line number Diff line change 1+ # -*- coding:utf-8 -*-
Original file line number Diff line number Diff line change 1+ # -*- coding:utf-8 -*-
2+
3+ import os
4+ import shutil
5+ import tempfile
6+ import pytest
7+
8+
9+ @pytest .fixture (scope = "session" )
10+ def _temp_dir ():
11+ ''' _temp_dir '''
12+ temp = tempfile .mkdtemp (prefix = 'argprase-' )
13+ print ('\n ' )
14+ print ('the current temp dir is {}' .format (temp ))
15+ yield temp
16+ shutil .rmtree (temp )
17+
18+
19+ @pytest .fixture (scope = "session" )
20+ def _temp_file ():
21+ ''' _temp_file '''
22+ fd , temp = tempfile .mkstemp (prefix = 'argprase-' , suffix = '.tmp' )
23+ # print('\n')
24+ print ('the current temp path is {}' .format (temp ))
25+ yield temp
26+ os .remove (temp )
27+
28+
29+ @pytest .fixture ()
30+ def cleandir ():
31+ ''' cleandir '''
32+ newpath = tempfile .mkdtemp ()
33+ os .chdir (newpath )
34+ print ('\n the current temp dir is {}' .format (newpath ))
35+
36+
37+ # @pytest.mark.xfail(raises=ZeroDivisionError)
38+ # def test_zero_division():
39+ # ''' test zero division'''
40+ # 1/0
41+ # with pytest.raises(ZeroDivisionError):
42+ # 1 / 0
Original file line number Diff line number Diff line change 1+ # -*- coding:utf-8 -*-
2+
3+ import os
4+ import pytest
5+
6+
7+ class DB (object ):
8+ ''' db '''
9+ def __init__ (self ):
10+ self .intransaction = []
11+
12+ def begin (self , name ):
13+ ''' begin '''
14+ print ('\n DB::begin: {}' .format (name ))
15+ self .intransaction .append (name )
16+
17+ def rollback (self ):
18+ ''' rollback '''
19+ item = self .intransaction .pop ()
20+ print ('\n DB::rollback: {}' .format (item ))
21+
22+
23+ @pytest .fixture (scope = "module" )
24+ def db ():
25+ ''' db '''
26+ return DB ()
27+
28+
29+ class TestClass (object ):
30+ ''' TestClass '''
31+ @pytest .fixture (autouse = True )
32+ def transact (self , request , db ):
33+ ''' transact '''
34+ db .begin (request .function .__name__ )
35+ yield
36+ db .rollback ()
37+
38+ def test_method1 (self , db ):
39+ ''' test_method1 '''
40+ print ('\n TestClass::test_method1: {}' .format (db ))
41+ assert db .intransaction == ["test_method1" ]
42+
43+ def test_method2 (self , db ):
44+ ''' test_method2 '''
45+ print ('\n TestClass::test_method2: {}' .format (db ))
46+ assert db .intransaction == ["test_method2" ]
47+
48+
49+ if __name__ == "__main__" :
50+ ''' the main point '''
51+ retcode = pytest .main (args = ['-v' , '-s' , os .path .abspath (__file__ )])
52+ # retcode = pytest.main(args=['--fixtures', os.path.abspath(__file__)])
53+ # retcode = pytest.main(args=['--collect-only', os.path.abspath(__file__)])
54+ print (retcode )
File renamed without changes.
File renamed without changes.
File renamed without changes.
You can’t perform that action at this time.
0 commit comments