Skip to content

Commit 3e153f2

Browse files
committed
Refactoring
1 parent 8b13307 commit 3e153f2

File tree

9 files changed

+57
-39
lines changed

9 files changed

+57
-39
lines changed

examples/fixtures/test_fixture_return_none/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,5 @@
2525

2626

2727
@pytest.fixture
28-
def test_fixture_setup_config_none():
28+
def test_fixture_return_none_config():
2929
LOGGER.warning(LOG_MESSAGE_SETUP)

examples/fixtures/test_fixture_return_none/test_fixture_return_none.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,5 @@
2525
# limitations under the License.
2626

2727

28-
def test_fixture_setup_none(test_fixture_setup_config_none):
29-
assert test_fixture_setup_config_none is None
28+
def test_fixture_setup_none(test_fixture_return_none_config):
29+
assert test_fixture_return_none_config is None

examples/fixtures/test_fixture_setup_failure/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@
2525

2626

2727
@pytest.fixture
28-
def fixture_setup_failure_config():
28+
def test_fixture_setup_failure_config():
2929
logging.error(LOG_MESSAGE_SETUP)
3030
raise Exception('Fixture setup failed')

examples/fixtures/test_fixture_setup_failure/test_fixture_setup_failure.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,6 @@
3535
LOG_MESSAGE_TEST = 'Log message for test of setup failure'
3636

3737

38-
def test_fixture_setup_failure(fixture_setup_failure_config):
38+
def test_fixture_setup_failure(test_fixture_setup_failure_config):
3939
logging.error(LOG_MESSAGE_TEST)
40-
assert fixture_setup_failure_config is not None
40+
assert test_fixture_setup_failure_config is not None

examples/fixtures/test_fixture_teardown_failure/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828

2929
@pytest.fixture
30-
def fixture_teardown_failure_config():
30+
def test_fixture_teardown_failure_config():
3131
logging.error(LOG_MESSAGE_BEFORE_YIELD)
3232
yield mock.Mock()
3333
logging.error(LOG_MESSAGE_TEARDOWN)

examples/fixtures/test_fixture_teardown_failure/test_fixture_teardown_failure.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@
2727
from time import sleep
2828

2929

30-
def test_fixture_teardown_failure(fixture_teardown_failure_config):
30+
def test_fixture_teardown_failure(test_fixture_teardown_failure_config):
3131
sleep(0.001)
32-
assert fixture_teardown_failure_config is not None
32+
assert test_fixture_teardown_failure_config is not None

examples/fixtures/test_fixture_yield_none/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@
2525

2626

2727
@pytest.fixture
28-
def test_fixture_setup_yield_none():
28+
def test_fixture_yield_none_config():
2929
LOGGER.warning(LOG_MESSAGE_SETUP)
3030
yield None

examples/fixtures/test_fixture_yield_none/test_fixture_yield_none.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,5 @@
2525
# limitations under the License.
2626

2727

28-
def test_fixture_yield_none(test_fixture_setup_yield_none):
29-
assert test_fixture_setup_yield_none is None
28+
def test_fixture_yield_none(test_fixture_yield_none_config):
29+
assert test_fixture_yield_none_config is None

tests/integration/test_fixtures.py

Lines changed: 45 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def test_fixture_setup(mock_client_init):
8686
variables = dict(utils.DEFAULT_VARIABLES)
8787
variables['rp_report_fixtures'] = True
8888
test_path = 'examples/fixtures/test_fixture_setup'
89-
result = utils.run_pytest_tests(tests=['examples/fixtures/test_fixture_setup'], variables=variables)
89+
result = utils.run_pytest_tests(tests=[test_path], variables=variables)
9090
assert int(result) == 0, 'Exit code should be 0 (no errors)'
9191

9292
start_count = mock_client.start_test_item.call_count
@@ -183,7 +183,8 @@ def test_fixture_setup_failure(mock_client_init):
183183

184184
variables = dict(utils.DEFAULT_VARIABLES)
185185
variables['rp_report_fixtures'] = True
186-
result = utils.run_pytest_tests(tests=['examples/fixtures/test_fixture_setup_failure'], variables=variables)
186+
test_path = 'examples/fixtures/test_fixture_setup_failure'
187+
result = utils.run_pytest_tests(tests=[test_path], variables=variables)
187188
assert int(result) == 1, 'Exit code should be 1 (test failure)'
188189

189190
start_count = mock_client.start_test_item.call_count
@@ -195,7 +196,8 @@ def test_fixture_setup_failure(mock_client_init):
195196

196197
call_args = mock_client.start_test_item.call_args_list
197198
setup_call_args = call_args[1][0]
198-
step_name = 'function fixture setup: fixture_setup_failure_config'
199+
fixture_name = f'{test_path.split("/")[-1]}_config'
200+
step_name = f'function fixture setup: {fixture_name}'
199201
assert setup_call_args[0] == step_name
200202

201203
setup_call_kwargs = call_args[1][1]
@@ -230,7 +232,8 @@ def test_fixture_teardown_failure(mock_client_init):
230232

231233
variables = dict(utils.DEFAULT_VARIABLES)
232234
variables['rp_report_fixtures'] = True
233-
result = utils.run_pytest_tests(tests=['examples/fixtures/test_fixture_teardown_failure'], variables=variables)
235+
test_path = 'examples/fixtures/test_fixture_teardown_failure'
236+
result = utils.run_pytest_tests(tests=[test_path], variables=variables)
234237
assert int(result) == 1, 'Exit code should be 1 (test failure)'
235238

236239
start_count = mock_client.start_test_item.call_count
@@ -239,14 +242,15 @@ def test_fixture_teardown_failure(mock_client_init):
239242

240243
call_args = mock_client.start_test_item.call_args_list
241244
setup_call_args = call_args[1][0]
242-
setup_step_name = 'function fixture setup: fixture_teardown_failure_config'
245+
fixture_name = f'{test_path.split("/")[-1]}_config'
246+
setup_step_name = f'function fixture setup: {fixture_name}'
243247
assert setup_call_args[0] == setup_step_name
244248

245249
setup_call_kwargs = call_args[1][1]
246250
assert not setup_call_kwargs['has_stats']
247251

248252
teardown_call_args = call_args[-1][0]
249-
teardown_step_name = 'function fixture teardown: fixture_teardown_failure_config'
253+
teardown_step_name = f'function fixture teardown: {fixture_name}'
250254
assert teardown_call_args[0] == teardown_step_name
251255

252256
setup_call_kwargs = call_args[-1][1]
@@ -290,7 +294,8 @@ def test_fixture_yield_none(mock_client_init):
290294

291295
variables = dict(utils.DEFAULT_VARIABLES)
292296
variables['rp_report_fixtures'] = True
293-
result = utils.run_pytest_tests(tests=['examples/fixtures/test_fixture_yield_none'], variables=variables)
297+
test_path = 'examples/fixtures/test_fixture_yield_none'
298+
result = utils.run_pytest_tests(tests=[test_path], variables=variables)
294299
assert int(result) == 0, 'Exit code should be 0 (no errors)'
295300

296301
start_count = mock_client.start_test_item.call_count
@@ -299,14 +304,15 @@ def test_fixture_yield_none(mock_client_init):
299304

300305
call_args = mock_client.start_test_item.call_args_list
301306
setup_call_args = call_args[1][0]
302-
setup_step_name = 'function fixture setup: test_fixture_setup_yield_none'
307+
fixture_name = f'{test_path.split("/")[-1]}_config'
308+
setup_step_name = f'function fixture setup: {fixture_name}'
303309
assert setup_call_args[0] == setup_step_name
304310

305311
setup_call_kwargs = call_args[1][1]
306312
assert not setup_call_kwargs['has_stats']
307313

308314
teardown_call_args = call_args[-1][0]
309-
teardown_step_name = 'function fixture teardown: test_fixture_setup_yield_none'
315+
teardown_step_name = f'function fixture teardown: {fixture_name}'
310316
assert teardown_call_args[0] == teardown_step_name
311317

312318
setup_call_kwargs = call_args[-1][1]
@@ -334,7 +340,8 @@ def test_fixture_return_none(mock_client_init):
334340

335341
variables = dict(utils.DEFAULT_VARIABLES)
336342
variables['rp_report_fixtures'] = True
337-
result = utils.run_pytest_tests(tests=['examples/fixtures/test_fixture_return_none'], variables=variables)
343+
test_path = 'examples/fixtures/test_fixture_return_none'
344+
result = utils.run_pytest_tests(tests=[test_path], variables=variables)
338345
assert int(result) == 0, 'Exit code should be 0 (no errors)'
339346

340347
start_count = mock_client.start_test_item.call_count
@@ -343,14 +350,15 @@ def test_fixture_return_none(mock_client_init):
343350

344351
call_args = mock_client.start_test_item.call_args_list
345352
setup_call_args = call_args[1][0]
346-
setup_step_name = 'function fixture setup: test_fixture_setup_config_none'
353+
fixture_name = f'{test_path.split("/")[-1]}_config'
354+
setup_step_name = f'function fixture setup: {fixture_name}'
347355
assert setup_call_args[0] == setup_step_name
348356

349357
setup_call_kwargs = call_args[1][1]
350358
assert not setup_call_kwargs['has_stats']
351359

352360
teardown_call_args = call_args[-1][0]
353-
teardown_step_name = 'function fixture teardown: test_fixture_setup_config_none'
361+
teardown_step_name = f'function fixture teardown: {fixture_name}'
354362
assert teardown_call_args[0] == teardown_step_name
355363

356364
setup_call_kwargs = call_args[-1][1]
@@ -378,7 +386,8 @@ def test_failure_fixture_teardown(mock_client_init):
378386

379387
variables = dict(utils.DEFAULT_VARIABLES)
380388
variables['rp_report_fixtures'] = True
381-
result = utils.run_pytest_tests(tests=['examples/fixtures/test_failure_fixture_teardown'], variables=variables)
389+
test_path = 'examples/fixtures/test_failure_fixture_teardown'
390+
result = utils.run_pytest_tests(tests=[test_path], variables=variables)
382391
assert int(result) == 1, 'Exit code should be 1 (test failure)'
383392

384393
start_count = mock_client.start_test_item.call_count
@@ -387,14 +396,15 @@ def test_failure_fixture_teardown(mock_client_init):
387396

388397
call_args = mock_client.start_test_item.call_args_list
389398
setup_call_args = call_args[1][0]
390-
setup_step_name = 'function fixture setup: test_failure_fixture_teardown_config'
399+
fixture_name = f'{test_path.split("/")[-1]}_config'
400+
setup_step_name = f'function fixture setup: {fixture_name}'
391401
assert setup_call_args[0] == setup_step_name
392402

393403
setup_call_kwargs = call_args[1][1]
394404
assert not setup_call_kwargs['has_stats']
395405

396406
teardown_call_args = call_args[-1][0]
397-
teardown_step_name = 'function fixture teardown: test_failure_fixture_teardown_config'
407+
teardown_step_name = f'function fixture teardown: {fixture_name}'
398408
assert teardown_call_args[0] == teardown_step_name
399409

400410
setup_call_kwargs = call_args[-1][1]
@@ -435,7 +445,8 @@ def test_session_fixture_setup(mock_client_init):
435445

436446
variables = dict(utils.DEFAULT_VARIABLES)
437447
variables['rp_report_fixtures'] = True
438-
result = utils.run_pytest_tests(tests=['examples/fixtures/session_fixture_return'], variables=variables)
448+
test_path = 'examples/fixtures/session_fixture_return'
449+
result = utils.run_pytest_tests(tests=[test_path], variables=variables)
439450
assert int(result) == 0, 'Exit code should be 0 (no errors)'
440451

441452
start_count = mock_client.start_test_item.call_count
@@ -444,14 +455,15 @@ def test_session_fixture_setup(mock_client_init):
444455

445456
call_args = mock_client.start_test_item.call_args_list
446457
setup_call_args = call_args[1][0]
447-
step_name = 'session fixture setup: session_fixture_return_config'
458+
fixture_name = f'{test_path.split("/")[-1]}_config'
459+
step_name = f'session fixture setup: {fixture_name}'
448460
assert setup_call_args[0] == step_name
449461

450462
setup_call_kwargs = call_args[1][1]
451463
assert not setup_call_kwargs['has_stats']
452464

453465
teardown_call_args = call_args[-1][0]
454-
assert teardown_call_args[0] == 'session fixture teardown: session_fixture_return_config'
466+
assert teardown_call_args[0] == f'session fixture teardown: {fixture_name}'
455467

456468
setup_call_kwargs = call_args[-1][1]
457469
assert not setup_call_kwargs['has_stats']
@@ -465,7 +477,8 @@ def test_package_fixture_setup(mock_client_init):
465477

466478
variables = dict(utils.DEFAULT_VARIABLES)
467479
variables['rp_report_fixtures'] = True
468-
result = utils.run_pytest_tests(tests=['examples/fixtures/package_fixture_return'], variables=variables)
480+
test_path = 'examples/fixtures/package_fixture_return'
481+
result = utils.run_pytest_tests(tests=[test_path], variables=variables)
469482
assert int(result) == 0, 'Exit code should be 0 (no errors)'
470483

471484
start_count = mock_client.start_test_item.call_count
@@ -474,14 +487,15 @@ def test_package_fixture_setup(mock_client_init):
474487

475488
call_args = mock_client.start_test_item.call_args_list
476489
setup_call_args = call_args[1][0]
477-
step_name = 'package fixture setup: package_fixture_return_config'
490+
fixture_name = f'{test_path.split("/")[-1]}_config'
491+
step_name = f'package fixture setup: {fixture_name}'
478492
assert setup_call_args[0] == step_name
479493

480494
setup_call_kwargs = call_args[1][1]
481495
assert not setup_call_kwargs['has_stats']
482496

483497
teardown_call_args = call_args[-1][0]
484-
assert teardown_call_args[0] == 'package fixture teardown: package_fixture_return_config'
498+
assert teardown_call_args[0] == f'package fixture teardown: {fixture_name}'
485499

486500
setup_call_kwargs = call_args[-1][1]
487501
assert not setup_call_kwargs['has_stats']
@@ -495,7 +509,8 @@ def test_module_fixture_setup(mock_client_init):
495509

496510
variables = dict(utils.DEFAULT_VARIABLES)
497511
variables['rp_report_fixtures'] = True
498-
result = utils.run_pytest_tests(tests=['examples/fixtures/module_fixture_return'], variables=variables)
512+
test_path = 'examples/fixtures/module_fixture_return'
513+
result = utils.run_pytest_tests(tests=[test_path], variables=variables)
499514
assert int(result) == 0, 'Exit code should be 0 (no errors)'
500515

501516
start_count = mock_client.start_test_item.call_count
@@ -504,14 +519,15 @@ def test_module_fixture_setup(mock_client_init):
504519

505520
call_args = mock_client.start_test_item.call_args_list
506521
setup_call_args = call_args[1][0]
507-
step_name = 'module fixture setup: module_fixture_return_config'
522+
fixture_name = f'{test_path.split("/")[-1]}_config'
523+
step_name = f'module fixture setup: {fixture_name}'
508524
assert setup_call_args[0] == step_name
509525

510526
setup_call_kwargs = call_args[1][1]
511527
assert not setup_call_kwargs['has_stats']
512528

513529
teardown_call_args = call_args[-1][0]
514-
assert teardown_call_args[0] == 'module fixture teardown: module_fixture_return_config'
530+
assert teardown_call_args[0] == f'module fixture teardown: {fixture_name}'
515531

516532
setup_call_kwargs = call_args[-1][1]
517533
assert not setup_call_kwargs['has_stats']
@@ -525,7 +541,8 @@ def test_class_fixture_setup(mock_client_init):
525541

526542
variables = dict(utils.DEFAULT_VARIABLES)
527543
variables['rp_report_fixtures'] = True
528-
result = utils.run_pytest_tests(tests=['examples/fixtures/class_fixture_return'], variables=variables)
544+
test_path = 'examples/fixtures/class_fixture_return'
545+
result = utils.run_pytest_tests(tests=[test_path], variables=variables)
529546
assert int(result) == 0, 'Exit code should be 0 (no errors)'
530547

531548
start_count = mock_client.start_test_item.call_count
@@ -534,7 +551,8 @@ def test_class_fixture_setup(mock_client_init):
534551

535552
call_args = mock_client.start_test_item.call_args_list
536553
setup_call_args = call_args[1][0]
537-
step_name = 'class fixture setup: class_fixture_return_config'
554+
fixture_name = f'{test_path.split("/")[-1]}_config'
555+
step_name = f'class fixture setup: {fixture_name}'
538556
assert setup_call_args[0] == step_name
539557
setup_call_kwargs = call_args[1][1]
540558
assert not setup_call_kwargs['has_stats']
@@ -544,7 +562,7 @@ def test_class_fixture_setup(mock_client_init):
544562
setup_call_kwargs = call_args[-3][1]
545563
assert not setup_call_kwargs['has_stats']
546564

547-
teardown_step_name = 'class fixture teardown: class_fixture_return_config'
565+
teardown_step_name = f'class fixture teardown: {fixture_name}'
548566
teardown_call_args = call_args[-5][0]
549567
assert teardown_call_args[0] == teardown_step_name
550568
setup_call_kwargs = call_args[-5][1]

0 commit comments

Comments
 (0)