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