@@ -30,37 +30,46 @@ def hsproject(hsclient):
3030 return hsclient .get_project (TEST_PROJECT_ID )
3131
3232
33+ #@my_vcr.use_cassette()
3334@pytest .fixture (scope = 'session' )
3435def hsspiderid (hsproject ):
3536 return str (hsproject .ids .spider (TEST_SPIDER_NAME , create = 1 ))
3637
3738
38- @pytest .fixture (scope = 'session' )
39- def hscollection (hsproject ):
40- return hsproject .collections .new_store (TEST_COLLECTION_NAME )
41-
4239
43- @my_vcr .use_cassette ()
40+ # @my_vcr.use_cassette()
4441@pytest .fixture (autouse = True , scope = 'session' )
4542def setup_session (hsclient , hsproject , hscollection ):
46- _set_testbotgroup (hsproject )
43+ set_testbotgroup (hsproject )
4744 yield
48- _unset_testbotgroup (hsproject )
45+ remove_all_jobs (hsproject )
46+ unset_testbotgroup (hsproject )
4947 hsclient .close ()
5048
5149
5250@pytest .fixture (autouse = True )
53- def setup_vcrpy_per_test (request , hsproject , hscollection ):
51+ def setup_vcrpy_per_test (request , hsproject ):
5452 # generates names like "test_module/test_function.yaml"
5553 # vcrpy creates the cassetes automatically under VCR_CASSETES_DIR
5654 cassette_name = '{}/{}.yaml' .format (
5755 request .function .__module__ .split ('.' )[- 1 ],
5856 request .function .__name__
5957 )
60- with my_vcr .use_cassette (cassette_name ):
61- clean_environment (hsproject , hscollection )
62- yield
63- clean_environment (hsproject , hscollection )
58+ #with my_vcr.use_cassette(cassette_name):
59+ remove_all_jobs (hsproject )
60+ yield
61+
62+
63+ #@my_vcr.use_cassette()
64+ @pytest .fixture (scope = 'session' )
65+ def hscollection (hsproject ):
66+ collection = hsproject .collections .new_store (TEST_COLLECTION_NAME )
67+ for item in collection .iter_values ():
68+ collection .delete (item ['_key' ])
69+ yield collection
70+ # drop all items in test collection
71+ for item in collection .iter_values ():
72+ collection .delete (item ['_key' ])
6473
6574# ----------------------------------------------------------------------------
6675
@@ -76,17 +85,7 @@ def start_job(hsproject, **startparams):
7685# Clean environment section
7786
7887
79- def clean_environment (hsproject , hscollection ):
80- _remove_all_jobs (hsproject )
81- # drop all items in test collection
82- for item in hscollection .iter_values ():
83- hscollection .delete (item ['_key' ])
84- # delete frontier slot
85- frontier = hsproject .frontier
86- frontier .delete_slot (TEST_FRONTIER_NAME , TEST_FRONTIER_SLOT )
87-
88-
89- def _remove_all_jobs (hsproject ):
88+ def remove_all_jobs (hsproject ):
9089 for k in list (hsproject .settings .keys ()):
9190 if k != 'botgroups' :
9291 del hsproject .settings [k ]
@@ -113,15 +112,15 @@ def _remove_job(hsproject, jobkey):
113112# Botgroups helpers section
114113
115114
116- def _set_testbotgroup (hsproject ):
115+ def set_testbotgroup (hsproject ):
117116 hsproject .settings .apipost (jl = {'botgroups' : [TEST_BOTGROUP ]})
118117 # Additional step to populate JobQ's botgroups table
119118 url = urlpathjoin (TEST_ENDPOINT , 'botgroups' , TEST_BOTGROUP , 'max_running' )
120119 requests .post (url , auth = hsproject .auth , data = 'null' )
121120 hsproject .settings .expire ()
122121
123122
124- def _unset_testbotgroup (hsproject ):
123+ def unset_testbotgroup (hsproject ):
125124 hsproject .settings .apidelete ('botgroups' )
126125 hsproject .settings .expire ()
127126 # Additional step to delete botgroups in JobQ
0 commit comments