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