Mercurial > p > roundup > code
comparison test/test_liveserver.py @ 8270:c70ffbc2a003
test: Override Fuzz timeout from env variable.
I have a local pytest.ini where I use:
env =
pytest_fuzz_timeout=30000
to set a 30 second timout while keeping the default 10 second for CI
because my machine is slow.
So the test now looks for that env variable and uses it if set.
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Sun, 12 Jan 2025 14:14:09 -0500 |
| parents | 05d8806b25ad |
| children | 669dfccca898 |
comparison
equal
deleted
inserted
replaced
| 8269:341841a9edc5 | 8270:c70ffbc2a003 |
|---|---|
| 223 @skip_hypothesis | 223 @skip_hypothesis |
| 224 class FuzzGetUrls(WsgiSetup, ClientSetup): | 224 class FuzzGetUrls(WsgiSetup, ClientSetup): |
| 225 | 225 |
| 226 _max_examples = 100 | 226 _max_examples = 100 |
| 227 | 227 |
| 228 # Timeout for each fuzz test in ms. Use env variable in local | |
| 229 # pytest.ini if your dev environment can't complete in the default | |
| 230 # 10 seconds. | |
| 231 fuzz_deadline = int(os.environ.get('pytest_fuzz_timeout', 0)) or 10000 | |
| 232 | |
| 228 @given(sampled_from(['@verbose', '@page_size', '@page_index']), | 233 @given(sampled_from(['@verbose', '@page_size', '@page_index']), |
| 229 text(min_size=1)) | 234 text(min_size=1)) |
| 230 @example("@verbose", "1#") | 235 @example("@verbose", "1#") |
| 231 @example("@verbose", "#1stuff") | 236 @example("@verbose", "#1stuff") |
| 232 @settings(max_examples=_max_examples, | 237 @settings(max_examples=_max_examples, |
| 233 deadline=10000) # in ms | 238 deadline=fuzz_deadline) # in ms |
| 234 def test_class_url_param_accepting_integer_values(self, param, value): | 239 def test_class_url_param_accepting_integer_values(self, param, value): |
| 235 """Tests all integer args for rest url. @page_* is the | 240 """Tests all integer args for rest url. @page_* is the |
| 236 same code for all *. | 241 same code for all *. |
| 237 """ | 242 """ |
| 238 session, _response = self.create_login_session() | 243 session, _response = self.create_login_session() |
| 256 | 261 |
| 257 @given(sampled_from(['@verbose']), text(min_size=1)) | 262 @given(sampled_from(['@verbose']), text(min_size=1)) |
| 258 @example("@verbose", "10#") | 263 @example("@verbose", "10#") |
| 259 @example("@verbose", u'Ø\U000dd990') | 264 @example("@verbose", u'Ø\U000dd990') |
| 260 @settings(max_examples=_max_examples, | 265 @settings(max_examples=_max_examples, |
| 261 deadline=10000) # in ms | 266 deadline=fuzz_deadline) # in ms |
| 262 def test_element_url_param_accepting_integer_values(self, param, value): | 267 def test_element_url_param_accepting_integer_values(self, param, value): |
| 263 """Tests args accepting int for rest url. | 268 """Tests args accepting int for rest url. |
| 264 """ | 269 """ |
| 265 session, _response = self.create_login_session() | 270 session, _response = self.create_login_session() |
| 266 url = '%s/rest/data/status/1' % (self.url_base()) | 271 url = '%s/rest/data/status/1' % (self.url_base()) |
| 279 self.assertEqual(f.status_code, 200) | 284 self.assertEqual(f.status_code, 200) |
| 280 else: | 285 else: |
| 281 # invalid value for param | 286 # invalid value for param |
| 282 self.assertEqual(f.status_code, 400) | 287 self.assertEqual(f.status_code, 400) |
| 283 | 288 |
| 289 @skip_hypothesis | |
| 290 class FuzzTestSettingData(WsgiSetup, ClientSetup): | |
| 291 | |
| 292 _max_examples = 100 | |
| 293 | |
| 294 # Timeout for each fuzz test in ms. Use env variable in local | |
| 295 # pytest.ini if your dev environment can't complete in the default | |
| 296 # 10 seconds. | |
| 297 fuzz_deadline = int(os.environ.get('pytest_fuzz_timeout', 0)) or 10000 | |
| 298 | |
| 284 @given(emails()) | 299 @given(emails()) |
| 285 @settings(max_examples=_max_examples, | 300 @settings(max_examples=_max_examples, |
| 286 deadline=10000) # in ms | 301 deadline=fuzz_deadline) # in ms |
| 287 def test_email_param(self,email): | 302 def test_setting_email_param(self,email): |
| 288 session, _response = self.create_login_session() | 303 session, _response = self.create_login_session() |
| 289 url = '%s/rest/data/user/1/address' % (self.url_base()) | 304 url = '%s/rest/data/user/1/address' % (self.url_base()) |
| 290 headers = {"Accept": "application/json", | 305 headers = {"Accept": "application/json", |
| 291 "Content-Type": "application/json", | 306 "Content-Type": "application/json", |
| 292 "x-requested-with": "rest", | 307 "x-requested-with": "rest", |
