3131from tests .conftest import REGION_NAME , RDSTestingInstance , S3TestingBucket
3232
3333
34- @pytest .fixture (scope = "module " )
34+ @pytest .fixture (scope = "session " )
3535def username () -> str :
3636 return "test_user"
3737
3838
39- @pytest .fixture (scope = "module " )
39+ @pytest .fixture (scope = "session " )
4040def user_email () -> str :
4141 return "user@example.com"
4242
4343
44- @pytest .fixture (scope = "module " )
44+ @pytest .fixture (scope = "session " )
4545def base_user_dir () -> str :
4646 return "test_user_dir"
4747
4848
49- @pytest .fixture (scope = "module " )
49+ @pytest .fixture (scope = "session " )
5050def internal_api_key_secret () -> str :
5151 return "test_internal_api_key"
5252
5353
54- @pytest .fixture (scope = "module " )
54+ @pytest .fixture (scope = "session " )
5555def application () -> dict [str , str ]:
5656 return {"application" : "app" , "version" : "latest" , "entrypoint" : "test" }
5757
5858
5959@pytest .fixture (
60- scope = "module " ,
60+ scope = "session " ,
6161 params = ["local" , pytest .param ("aws" , marks = pytest .mark .aws )],
6262)
63- def env (request : pytest .FixtureRequest ) -> str :
64- return cast (str , request .param )
63+ def env (
64+ request : pytest .FixtureRequest ,
65+ rds_testing_instance : RDSTestingInstance ,
66+ s3_testing_bucket : S3TestingBucket ,
67+ ) -> Generator [str , Any , None ]:
68+ env = cast (str , request .param )
69+ if env == "aws" :
70+ rds_testing_instance .create ()
71+ s3_testing_bucket .create ()
72+ yield env
73+ if env == "aws" :
74+ rds_testing_instance .delete ()
75+ s3_testing_bucket .delete ()
6576
6677
6778@pytest .fixture
68- def db_session (env : str ) -> Generator [Session , Any , None ]:
79+ def db_session (
80+ env : str , rds_testing_instance : RDSTestingInstance
81+ ) -> Generator [Session , Any , None ]:
6982 if env == "local" :
7083 rel_test_db_path = "./test_app.db"
7184 shutil .rmtree (rel_test_db_path , ignore_errors = True )
7285 engine = create_engine (
7386 f"sqlite:///{ rel_test_db_path } " , connect_args = {"check_same_thread" : False }
7487 )
7588 elif env == "aws" :
76- rds_instance = RDSTestingInstance ("decodecloudintegrationtestsuserapi" )
77- engine = rds_instance .engine
89+ engine = rds_testing_instance .engine
7890 else :
7991 raise NotImplementedError
8092
@@ -85,15 +97,15 @@ def db_session(env: str) -> Generator[Session, Any, None]:
8597 if env == "local" :
8698 os .remove (rel_test_db_path )
8799 elif env == "aws" :
88- rds_instance .cleanup ()
100+ rds_testing_instance .cleanup ()
89101
90102
91103@pytest .fixture
92104def base_filesystem (
93105 env : str ,
94106 base_user_dir : str ,
95107 monkeypatch_module : pytest .MonkeyPatch ,
96- bucket_suffix : str ,
108+ s3_testing_bucket : S3TestingBucket ,
97109) -> Generator [FileSystem , Any , None ]:
98110 if env == "local" :
99111 base_user_dir = f"./{ base_user_dir } "
@@ -120,17 +132,16 @@ def base_filesystem(
120132 shutil .rmtree (base_user_dir , ignore_errors = True )
121133
122134 elif env == "aws" :
123- testing_bucket = S3TestingBucket (bucket_suffix )
124135 # Update settings to use the actual unique bucket name created by S3TestingBucket
125136 monkeypatch_module .setattr (
126137 settings ,
127138 "s3_bucket" ,
128- testing_bucket .bucket_name ,
139+ s3_testing_bucket .bucket_name ,
129140 )
130141 yield S3Filesystem (
131- base_user_dir , testing_bucket .s3_client , testing_bucket .bucket_name
142+ base_user_dir , s3_testing_bucket .s3_client , s3_testing_bucket .bucket_name
132143 )
133- testing_bucket .cleanup ()
144+ s3_testing_bucket .cleanup ()
134145
135146 else :
136147 raise NotImplementedError
@@ -163,7 +174,7 @@ def override_filesystem_dep(
163174 )
164175
165176
166- @pytest .fixture (autouse = True , scope = "module " )
177+ @pytest .fixture (autouse = True , scope = "session " )
167178def override_auth (
168179 monkeypatch_module : pytest .MonkeyPatch , username : str , user_email : str
169180) -> None :
@@ -174,7 +185,7 @@ def override_auth(
174185 )
175186
176187
177- @pytest .fixture (scope = "module " , autouse = True )
188+ @pytest .fixture (scope = "session " , autouse = True )
178189def override_internal_api_key_secret (
179190 monkeypatch_module : pytest .MonkeyPatch , internal_api_key_secret : str
180191) -> None :
@@ -185,7 +196,7 @@ def override_internal_api_key_secret(
185196 )
186197
187198
188- @pytest .fixture (scope = "module " , autouse = True )
199+ @pytest .fixture (scope = "session " , autouse = True )
189200def override_email_sender (monkeypatch_module : pytest .MonkeyPatch ) -> None :
190201 monkeypatch_module .setitem (
191202 app .dependency_overrides , # type: ignore
@@ -194,7 +205,7 @@ def override_email_sender(monkeypatch_module: pytest.MonkeyPatch) -> None:
194205 )
195206
196207
197- @pytest .fixture (scope = "module " , autouse = True )
208+ @pytest .fixture (scope = "session " , autouse = True )
198209def override_application_config (
199210 monkeypatch_module : pytest .MonkeyPatch , application : dict [str , str ]
200211) -> None :
0 commit comments