From e6fb0fe8bc75e7931fe86e95442eec09b49caee7 Mon Sep 17 00:00:00 2001 From: Adam Dangoor Date: Mon, 31 Jul 2017 19:45:24 +0100 Subject: [PATCH 3/3] Catch and test pytest warning --- pytest.ini | 2 -- tests/test_compat.py | 15 +++++++++++++-- 2 files changed, 13 insertions(+), 4 deletions(-) delete mode 100644 pytest.ini diff --git a/pytest.ini b/pytest.ini deleted file mode 100644 index 1ceab94..0000000 --- a/pytest.ini +++ /dev/null @@ -1,2 +0,0 @@ -[pytest] -addopts = -p no:warnings diff --git a/tests/test_compat.py b/tests/test_compat.py index e4ecdc8..d86110a 100644 --- a/tests/test_compat.py +++ b/tests/test_compat.py @@ -1,3 +1,5 @@ +import pytest + import click @@ -11,10 +13,19 @@ if click.__version__ >= '3.0': def cli(foo): click.echo(foo) - result = runner.invoke(cli, ['--foo', 'wat']) + with pytest.warns(Warning) as records: + result = runner.invoke(cli, ['--foo', 'wat']) + + [warning_record] = records + warning_message = str(warning_record.message) + assert 'Invoked legacy parameter callback' in warning_message assert result.exit_code == 0 + # Depending on the pytest version, the warning message may be + # in `result.output`. + # + # In pytest version 3.1 pytest started capturing warnings by default. + # See https://docs.pytest.org/en/latest/warnings.html#warnings-capture. assert 'WAT' in result.output - assert 'Invoked legacy parameter callback' in result.output def test_bash_func_name(): -- 2.14.2