From 91ac88774d88fef4d09a14a6a1b625724d75c2a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iv=C3=A0n=20Todorovich?= Date: Mon, 11 Sep 2023 13:29:15 -0300 Subject: [PATCH] [FIX] tests: use pattern matching Some other warnings (DeprecationWarning) were being logged and thus the `len` assertions failed. Using match is actually better for this purpose, as we only want to check if that particular warning is logged, doesn't matter if others are logged too. --- tests/test_migration_file.py | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/tests/test_migration_file.py b/tests/test_migration_file.py index 8f39b3b..971e6c7 100644 --- a/tests/test_migration_file.py +++ b/tests/test_migration_file.py @@ -118,7 +118,7 @@ def test_example_file_output_mode(runner_gen, request, capfd): def test_example_no_setup_file_output(runner_gen, request, capfd): - with pytest.warns(FutureWarning) as record: + with pytest.warns(FutureWarning, match='First version should be named `setup`'): runner = runner_gen('migration_no_backup.yml') runner.perform() expected = ( @@ -156,13 +156,9 @@ def test_example_no_setup_file_output(runner_gen, request, capfd): ) assert expected == capfd.readouterr() - assert 1 == len(record) - warnings_msg = u'First version should be named `setup`' - assert warnings_msg == record[0].message.args[0] - def test_example_no_setup_file_output_mode(runner_gen, request, capfd): - with pytest.warns(FutureWarning) as record: + with pytest.warns(FutureWarning, match='First version should be named `setup`'): runner = runner_gen('migration_no_backup.yml', mode='prod') runner.perform() expected = ( @@ -207,10 +203,6 @@ def test_example_no_setup_file_output_mode(runner_gen, request, capfd): ) assert expected == capfd.readouterr() - assert 1 == len(record) - warnings_msg = u'First version should be named `setup`' - assert warnings_msg == record[0].message.args[0] - def test_mixed_digits_output_mode(runner_gen, request, capfd): old_versions = [