1
+ import datetime
2
+ import os
1
3
import pytest
4
+ import allure
5
+ import glob
6
+ from Library .store import Store
2
7
3
8
4
9
@pytest .fixture (autouse = True )
5
10
def before_each ():
6
11
print ('*-* Before each INITIALIZATION' )
7
- yield
12
+ try :
13
+ yield
14
+ for driver in Store .drivers :
15
+ root_dir = os .path .dirname (os .path .abspath (__file__ )).replace ("/Tests" , "" )
16
+ config_path = root_dir + '/reports/screenshots/img%s.png' % datetime .datetime .now ().strftime ("%Y%m%d-%H%M%S" )
17
+ driver .save_screenshot (config_path )
18
+ name = 'img%s.png' % datetime .datetime .now ().strftime ("%Y%m%d-%H%M%S" )
19
+ allure .attach (config_path , name = name , attachment_type = "PNG" )
20
+ except Exception as e :
21
+ print (e )
8
22
print ('*-* After each END' )
9
23
10
24
11
25
@pytest .fixture (scope = 'module' , autouse = True )
12
26
def before_module ():
13
27
print ('*-* Before module INITIALIZATION' )
14
28
yield
29
+ for driver in Store .drivers :
30
+ driver .quit ()
15
31
print ('*-* After module END' )
16
32
17
33
@@ -21,27 +37,32 @@ def pytest_configure(config):
21
37
This hook is called for every plugin and initial conftest
22
38
file after command line options have been parsed.
23
39
"""
24
- print ("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ pytest_configure" )
40
+ print ("*-* pytest_configure" )
41
+ root_dir = os .path .dirname (os .path .abspath (__file__ )).replace ("/Tests" , "" )
42
+ config_path = root_dir + '/reports/screenshots/*.png'
43
+ for CleanUp in glob .glob (config_path ):
44
+ print (CleanUp )
45
+ os .remove (CleanUp )
25
46
26
47
27
48
def pytest_sessionstart (session ):
28
49
"""
29
50
Called after the Session object has been created and
30
51
before performing collection and entering the run test loop.
31
52
"""
32
- print ("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ pytest_sessionstart" )
53
+ print ("*-* pytest_sessionstart" )
33
54
34
55
35
56
def pytest_sessionfinish (session , exitstatus ):
36
57
"""
37
58
Called after whole test run finished, right before
38
59
returning the exit status to the system.
39
60
"""
40
- print ("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ pytest_sessionfinish" )
61
+ print ("*-* pytest_sessionfinish" )
41
62
42
63
43
64
def pytest_unconfigure (config ):
44
65
"""
45
66
called before test process is exited.
46
67
"""
47
- print ("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ pytest_unconfigure" )
68
+ print ("*-* pytest_unconfigure" )
0 commit comments