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