Skip to content

Commit

Permalink
[FIX] tests: use pattern matching
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ivantodorovich committed Sep 11, 2023
1 parent 88d3d98 commit 6d2a58c
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions tests/test_migration_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ 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:
msg = 'First version should be named `setup`'
with pytest.warns(FutureWarning, match=msg):
runner = runner_gen('migration_no_backup.yml')
runner.perform()
expected = (
Expand Down Expand Up @@ -156,13 +157,10 @@ 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:
msg = 'First version should be named `setup`'
with pytest.warns(FutureWarning, match=msg):
runner = runner_gen('migration_no_backup.yml', mode='prod')
runner.perform()
expected = (
Expand Down Expand Up @@ -207,10 +205,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 = [
Expand Down

0 comments on commit 6d2a58c

Please sign in to comment.