Fix warning test to allow to unpin pytest
We worked around a new release of pytest in https://review.openstack.org/#/c/468044/ that managed to break our test implementation that checked that we raised the right warning. Adapt the test to work with all versions of pytest. Change-Id: I1b1c66befdc072d1d95606085b0363fa4eaf00ef
This commit is contained in:
parent
cbd3ae1e9b
commit
b914452d40
@ -14,11 +14,13 @@
|
|||||||
|
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
|
import pytest
|
||||||
import shutil
|
import shutil
|
||||||
import six
|
import six
|
||||||
import sys
|
|
||||||
import tempfile
|
import tempfile
|
||||||
|
|
||||||
|
from distutils.version import LooseVersion
|
||||||
|
from flask_frozen import MissingURLGeneratorWarning
|
||||||
from lxml import etree
|
from lxml import etree
|
||||||
|
|
||||||
import ara.shell
|
import ara.shell
|
||||||
@ -656,19 +658,11 @@ class TestCLIGenerate(TestAra):
|
|||||||
# Create a temporary directory for ara generate tests
|
# Create a temporary directory for ara generate tests
|
||||||
self.generate_dir = tempfile.mkdtemp(prefix='ara')
|
self.generate_dir = tempfile.mkdtemp(prefix='ara')
|
||||||
|
|
||||||
# Buffer stderr for warning tests
|
|
||||||
self.stderr = sys.stderr
|
|
||||||
self.buffer = six.StringIO()
|
|
||||||
sys.stderr = self.buffer
|
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
super(TestCLIGenerate, self).tearDown()
|
super(TestCLIGenerate, self).tearDown()
|
||||||
# Remove the temporary ara generate directory
|
# Remove the temporary ara generate directory
|
||||||
shutil.rmtree(self.generate_dir)
|
shutil.rmtree(self.generate_dir)
|
||||||
|
|
||||||
# Reset stderr back to default
|
|
||||||
sys.stderr = self.stderr
|
|
||||||
|
|
||||||
def test_generate_empty_html(self):
|
def test_generate_empty_html(self):
|
||||||
""" Ensures the application is still rendered gracefully """
|
""" Ensures the application is still rendered gracefully """
|
||||||
self.app.config['ARA_IGNORE_EMPTY_GENERATION'] = False
|
self.app.config['ARA_IGNORE_EMPTY_GENERATION'] = False
|
||||||
@ -678,10 +672,18 @@ class TestCLIGenerate(TestAra):
|
|||||||
cmd = ara.cli.generate.GenerateHtml(shell, None)
|
cmd = ara.cli.generate.GenerateHtml(shell, None)
|
||||||
parser = cmd.get_parser('test')
|
parser = cmd.get_parser('test')
|
||||||
args = parser.parse_args([dir])
|
args = parser.parse_args([dir])
|
||||||
|
|
||||||
|
with pytest.warns(MissingURLGeneratorWarning) as warnings:
|
||||||
cmd.take_action(args)
|
cmd.take_action(args)
|
||||||
|
|
||||||
output = self.buffer.getvalue().strip()
|
# pytest 3.0 through 3.1 are backwards incompatible here
|
||||||
self.assertIn('MissingURLGeneratorWarning', output)
|
if LooseVersion(pytest.__version__) >= LooseVersion('3.1.0'):
|
||||||
|
cat = [item._category_name for item in warnings]
|
||||||
|
self.assertTrue(any('MissingURLGeneratorWarning' in c
|
||||||
|
for c in cat))
|
||||||
|
else:
|
||||||
|
self.assertTrue(any(MissingURLGeneratorWarning == w.category
|
||||||
|
for w in warnings))
|
||||||
|
|
||||||
paths = [
|
paths = [
|
||||||
os.path.join(dir, 'index.html'),
|
os.path.join(dir, 'index.html'),
|
||||||
|
@ -4,7 +4,7 @@ coverage
|
|||||||
flake8
|
flake8
|
||||||
ansible-lint
|
ansible-lint
|
||||||
mock
|
mock
|
||||||
pytest==3.0.7
|
pytest
|
||||||
pytest-cov
|
pytest-cov
|
||||||
sphinx!=1.2.0,!=1.3b1,<1.3,>=1.1.2
|
sphinx!=1.2.0,!=1.3b1,<1.3,>=1.1.2
|
||||||
sphinx-rtd-theme
|
sphinx-rtd-theme
|
||||||
|
Loading…
Reference in New Issue
Block a user