11import shutil
2- from typing import Any , Generator
2+ from typing import Any , Generator , cast
33
44import pytest
55
1818from workerfacing_api .main import workerfacing_app
1919
2020
21- @pytest .fixture (scope = "module " )
21+ @pytest .fixture (scope = "session " )
2222def test_username () -> str :
2323 return "test_user"
2424
2525
26- @pytest .fixture (scope = "module " )
26+ @pytest .fixture (scope = "session " )
2727def base_dir () -> str :
2828 return "int_test_dir"
2929
3030
31- @pytest .fixture (scope = "module " )
31+ @pytest .fixture (scope = "session " )
3232def internal_api_key_secret () -> str :
3333 return "test_internal_api_key"
3434
3535
3636@pytest .fixture (
37- scope = "module " ,
37+ scope = "session " ,
3838 params = ["local" , pytest .param ("aws" , marks = pytest .mark .aws )],
3939)
40- def env (request : pytest .FixtureRequest ) -> str :
41- assert isinstance (request .param , str )
42- return request .param
40+ def env (
41+ request : pytest .FixtureRequest ,
42+ rds_testing_instance : RDSTestingInstance ,
43+ s3_testing_bucket : S3TestingBucket ,
44+ ) -> Generator [str , Any , None ]:
45+ env = cast (str , request .param )
46+ if env == "aws" :
47+ rds_testing_instance .create ()
48+ s3_testing_bucket .create ()
49+ yield env
50+ if env == "aws" :
51+ rds_testing_instance .delete ()
52+ s3_testing_bucket .delete ()
4353
4454
45- @pytest .fixture (scope = "module " )
55+ @pytest .fixture (scope = "session " )
4656def base_filesystem (
47- env : str , base_dir : str , monkeypatch_module : pytest .MonkeyPatch , bucket_suffix : str
57+ env : str ,
58+ base_dir : str ,
59+ monkeypatch_module : pytest .MonkeyPatch ,
60+ s3_testing_bucket : S3TestingBucket ,
4861) -> Generator [FileSystem , Any , None ]:
4962 monkeypatch_module .setattr (
5063 settings ,
@@ -63,39 +76,39 @@ def base_filesystem(
6376 shutil .rmtree (base_dir , ignore_errors = True )
6477
6578 elif env == "aws" :
66- testing_bucket = S3TestingBucket (bucket_suffix )
6779 # Update settings to use the actual unique bucket name created by S3TestingBucket
6880 monkeypatch_module .setattr (
6981 settings ,
7082 "s3_bucket" ,
71- testing_bucket .bucket_name ,
83+ s3_testing_bucket .bucket_name ,
7284 )
73- yield S3Filesystem (testing_bucket .s3_client , testing_bucket .bucket_name )
74- testing_bucket .cleanup ()
85+ yield S3Filesystem (s3_testing_bucket .s3_client , s3_testing_bucket .bucket_name )
86+ s3_testing_bucket .cleanup ()
7587
7688 else :
7789 raise NotImplementedError
7890
7991
80- @pytest .fixture (scope = "module " )
92+ @pytest .fixture (scope = "session " )
8193def queue (
82- env : str , tmpdir_factory : pytest .TempdirFactory
94+ env : str ,
95+ rds_testing_instance : RDSTestingInstance ,
96+ tmpdir_factory : pytest .TempdirFactory ,
8397) -> Generator [RDSJobQueue , Any , None ]:
8498 if env == "local" :
8599 queue = RDSJobQueue (
86100 f"sqlite:///{ tmpdir_factory .mktemp ('integration' )} /local.db"
87101 )
88102 else :
89- db = RDSTestingInstance ("decodecloudintegrationtests" )
90- queue = RDSJobQueue (db .db_url )
103+ queue = RDSJobQueue (rds_testing_instance .db_url )
91104 queue .create (err_on_exists = True )
92105 yield queue
93106 queue .delete ()
94107 if env == "aws" :
95- db .cleanup ()
108+ rds_testing_instance .cleanup ()
96109
97110
98- @pytest .fixture (scope = "module " , autouse = True )
111+ @pytest .fixture (scope = "session " , autouse = True )
99112def override_filesystem_dep (
100113 base_filesystem : FileSystem , monkeypatch_module : pytest .MonkeyPatch
101114) -> None :
@@ -106,7 +119,7 @@ def override_filesystem_dep(
106119 )
107120
108121
109- @pytest .fixture (scope = "module " , autouse = True )
122+ @pytest .fixture (scope = "session " , autouse = True )
110123def override_queue_dep (
111124 queue : RDSJobQueue , monkeypatch_module : pytest .MonkeyPatch
112125) -> None :
@@ -117,7 +130,7 @@ def override_queue_dep(
117130 )
118131
119132
120- @pytest .fixture (scope = "module " , autouse = True )
133+ @pytest .fixture (scope = "session " , autouse = True )
121134def override_auth (monkeypatch_module : pytest .MonkeyPatch , test_username : str ) -> None :
122135 monkeypatch_module .setitem (
123136 workerfacing_app .dependency_overrides , # type: ignore
@@ -132,7 +145,7 @@ def override_auth(monkeypatch_module: pytest.MonkeyPatch, test_username: str) ->
132145 )
133146
134147
135- @pytest .fixture (scope = "module " , autouse = True )
148+ @pytest .fixture (scope = "session " , autouse = True )
136149def override_internal_api_key_secret (
137150 monkeypatch_module : pytest .MonkeyPatch , internal_api_key_secret : str
138151) -> str :
0 commit comments