Send a warning when a yaml filename has an underscore (#157)
TestSuites are grouped by test runners by the name that is generated for the tests within. To ease that grouping it is useful to have filenames with a known set of characters. Grouping is also used for py.test fixture handling. This change raises a warning if a filename has an '_' in it, effectively declaring that though it is possible to use '_', it can impact grouping. Fixes #144
This commit is contained in:
parent
5d8949257a
commit
895119af66
@ -29,8 +29,10 @@ import os
|
||||
import unittest
|
||||
from unittest import suite
|
||||
import uuid
|
||||
import warnings
|
||||
|
||||
from gabbi import case
|
||||
from gabbi import exception
|
||||
from gabbi import handlers
|
||||
from gabbi import reporter
|
||||
from gabbi import suitemaker
|
||||
@ -83,6 +85,10 @@ def build_tests(path, loader, host=None, port=8001, intercept=None,
|
||||
|
||||
top_suite = suite.TestSuite()
|
||||
for test_file in glob.iglob('%s/*.yaml' % path):
|
||||
if '_' in os.path.basename(test_file):
|
||||
warnings.warn(exception.GabbiSyntaxWarning(
|
||||
"'_' in test filename %s. This can break suite grouping."
|
||||
% test_file))
|
||||
if intercept:
|
||||
host = str(uuid.uuid4())
|
||||
suite_dict = utils.load_yaml(yaml_file=test_file)
|
||||
@ -134,7 +140,6 @@ def py_test_generator(test_dir, host=None, port=8001, intercept=None,
|
||||
def test_suite_from_yaml(loader, test_base_name, test_yaml, test_directory,
|
||||
host, port, fixture_module, intercept, prefix=''):
|
||||
"""Legacy wrapper retained for backwards compatibility."""
|
||||
import warnings
|
||||
|
||||
with warnings.catch_warnings(): # ensures warnings filter is restored
|
||||
warnings.simplefilter('default', DeprecationWarning)
|
||||
|
@ -16,3 +16,8 @@
|
||||
class GabbiFormatError(ValueError):
|
||||
"""An exception to encapsulate poorly formed test data."""
|
||||
pass
|
||||
|
||||
|
||||
class GabbiSyntaxWarning(SyntaxWarning):
|
||||
"""A warning about syntax that is not desirable."""
|
||||
pass
|
||||
|
41
gabbi/tests/test_syntax_warning.py
Normal file
41
gabbi/tests/test_syntax_warning.py
Normal file
@ -0,0 +1,41 @@
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
"""Test that the driver warns on bad yaml name."""
|
||||
|
||||
import os
|
||||
import unittest
|
||||
import warnings
|
||||
|
||||
from gabbi import driver
|
||||
from gabbi import exception
|
||||
|
||||
|
||||
TESTS_DIR = 'warning_gabbits'
|
||||
|
||||
|
||||
class DriverTest(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(DriverTest, self).setUp()
|
||||
self.loader = unittest.defaultTestLoader
|
||||
self.test_dir = os.path.join(os.path.dirname(__file__), TESTS_DIR)
|
||||
|
||||
def test_driver_warngs_on_files(self):
|
||||
with warnings.catch_warnings(record=True) as the_warnings:
|
||||
driver.build_tests(
|
||||
self.test_dir, self.loader, host='localhost', port=8001)
|
||||
self.assertEqual(1, len(the_warnings))
|
||||
the_warning = the_warnings[-1]
|
||||
self.assertEqual(
|
||||
the_warning.category, exception.GabbiSyntaxWarning)
|
||||
self.assertIn("'_' in test filename", str(the_warning.message))
|
6
gabbi/tests/warning_gabbits/underscore_sample.yaml
Normal file
6
gabbi/tests/warning_gabbits/underscore_sample.yaml
Normal file
@ -0,0 +1,6 @@
|
||||
|
||||
tests:
|
||||
- name: one
|
||||
url: /
|
||||
- name: two
|
||||
url: http://example.com/moo
|
Loading…
Reference in New Issue
Block a user