diff options
author | Eevee <eevee.git@veekun.com> | 2013-05-10 10:56:28 -0700 |
---|---|---|
committer | Eevee <eevee.git@veekun.com> | 2013-05-23 13:43:24 -0700 |
commit | 4b0a89c6ed7dcadb2ed34dd79e3a5ac3b12d9db3 (patch) | |
tree | 4a30624f4fadb4cea3a4a78cd77df9003ba2dc05 | |
parent | da4cc9125052473f6b149dc673bd212275509ec6 (diff) | |
download | pyscss-4b0a89c6ed7dcadb2ed34dd79e3a5ac3b12d9db3.tar.gz |
Add py.test wizardry for running a subset of file tests. Fixes #134.
-rw-r--r-- | conftest.py | 16 | ||||
-rw-r--r-- | scss/tests/conftest.py | 36 | ||||
-rw-r--r-- | scss/tests/test_files.py | 10 |
3 files changed, 54 insertions, 8 deletions
diff --git a/conftest.py b/conftest.py new file mode 100644 index 0000000..01b04d1 --- /dev/null +++ b/conftest.py @@ -0,0 +1,16 @@ +"""py.test plugin configuration.""" + +def pytest_addoption(parser): + """Add an option for filtering the file tests run. + + This has to be done in the project root; py.test doesn't (and can't) + recursively look for conftest.py files until after it's parsed the command + line. + """ + parser.addoption('--test-file-filter', + help='comma-separated regexes to select test files', + action='store', + type='string', + dest='test_file_filter', + default=None, + ) diff --git a/scss/tests/conftest.py b/scss/tests/conftest.py new file mode 100644 index 0000000..9a3b73b --- /dev/null +++ b/scss/tests/conftest.py @@ -0,0 +1,36 @@ +"""py.test plugin configuration.""" + +import glob +import os.path +import re + +FILES_DIR = os.path.join(os.path.dirname(__file__), 'files') + +def pytest_generate_tests(metafunc): + """Inject the test files as parametrizations. + + Relies on the command-line option `--test-file-filter`, set by the root + conftest.py. + """ + + scss_files = glob.glob(os.path.join(FILES_DIR, '*/*.scss')) + test_file_filter = metafunc.config.getoption('test_file_filter') + if test_file_filter: + file_filters = [ + re.compile(filt) + for filt in test_file_filter.split(',') + ] + + filtered_scss_files = [] + for fn in scss_files: + relfn = os.path.relpath(fn, FILES_DIR) + for rx in file_filters: + if rx.search(relfn): + filtered_scss_files.append(fn) + break + + scss_files = filtered_scss_files + + metafunc.parametrize( + 'scss_file_pair', + [(fn, fn[:-5] + '.css') for fn in scss_files]) diff --git a/scss/tests/test_files.py b/scss/tests/test_files.py index 882a027..04e15a3 100644 --- a/scss/tests/test_files.py +++ b/scss/tests/test_files.py @@ -22,16 +22,10 @@ logger = logging.getLogger('scss') logger.setLevel(logging.ERROR) logger.addHandler(console) -HERE = os.path.join(os.path.split(__file__)[0], 'files') +def test_pair_programmatic(scss_file_pair): + scss_fn, css_fn = scss_file_pair -@pytest.mark.parametrize( - ('scss_fn', 'css_fn'), [ - (scss_fn, os.path.splitext(scss_fn)[0] + '.css') - for scss_fn in glob.glob(os.path.join(HERE, '*/*.scss')) - ] -) -def test_pair(scss_fn, css_fn): with open(scss_fn) as fh: source = fh.read() with open(css_fn) as fh: |