Skip to content

Commit d7f539a

Browse files
committed
better skip reasons
1 parent 26e2039 commit d7f539a

File tree

1 file changed

+34
-68
lines changed

1 file changed

+34
-68
lines changed

tests/test_filters.py

+34-68
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ def subprocess(self, argv, out, data=None):
180180
def setup(self):
181181
if not hasattr(str, 'format'):
182182
# A large part of this functionality is not available on Python 2.5
183-
pytest.skip()
183+
pytest.skip("test not for py 2.5")
184184
self.patcher = patch('subprocess.Popen')
185185
self.popen = self.patcher.start()
186186
self.popen.return_value = Mock()
@@ -480,41 +480,35 @@ def test_cssmin(self):
480480
self.mkbundle('foo.css', filters='cssmin', output='out.css').build()
481481
except EnvironmentError:
482482
# cssmin is not installed, that's ok.
483-
pytest.skip()
483+
pytest.skip('no cssmin')
484484
assert self.get('out.css') == """h1{font-family:"Verdana";color:#FFF}"""
485485

486486
def test_cssutils(self):
487-
try:
488-
import cssutils
489-
except ImportError:
490-
pytest.skip()
487+
cssutils = pytest.importorskip('cssutils')
491488
self.mkbundle('foo.css', filters='cssutils', output='out.css').build()
492489
assert self.get('out.css') == """h1{font-family:"Verdana";color:#FFF}"""
493490

494491
def test_clevercss(self):
495-
try:
496-
import clevercss
497-
except ImportError:
498-
pytest.skip()
492+
clevercss = pytest.importorskip('clevercss')
499493
self.create_files({'in': """a:\n color: #fff.darken(50%)"""})
500494
self.mkbundle('in', filters='clevercss', output='out.css').build()
501495
assert self.get('out.css') == """a {\n color: #7f7f7f;\n}"""
502496

503497
def test_uglifyjs_ascii(self):
504498
if not find_executable('uglifyjs'):
505-
pytest.skip()
499+
pytest.skip('no uglifyjs')
506500
self.mkbundle('foo2.js', filters='uglifyjs', output='out.js').build()
507501
assert self.get('out.js') == 'more();'
508502

509503
def test_uglifyjs_unicode(self):
510504
if not find_executable('uglifyjs'):
511-
pytest.skip()
505+
pytest.skip('no uglifyjs')
512506
self.mkbundle('foo.js', filters='uglifyjs', output='out.js').build()
513507
assert self.get('out.js') == 'function foo(bar){var dummy;document.write(bar);var a="Ünícôdè"}'
514508

515509
def test_uglifyjs_ascii_and_unicode(self):
516510
if not find_executable('uglifyjs'):
517-
pytest.skip()
511+
pytest.skip('no uglifyjs')
518512
self.mkbundle('foo.js', 'foo2.js', filters='uglifyjs', output='out.js').build()
519513
assert self.get('out.js') == 'function foo(bar){var dummy;document.write(bar);var a="Ünícôdè"}more();'
520514

@@ -547,10 +541,7 @@ def test_less_ruby(self):
547541
assert self.get('out.css') == 'h1 {\n font-family: "Verdana";\n color: #ffffff;\n}\n'
548542

549543
def test_jsmin(self):
550-
try:
551-
import jsmin
552-
except ImportError:
553-
pytest.skip()
544+
jsmin = pytest.importorskip('jsmin')
554545
self.mkbundle('foo.js', filters='jsmin', output='out.js').build()
555546
assert self.get('out.js') in (
556547
# Builtin jsmin
@@ -562,10 +553,7 @@ def test_jsmin(self):
562553
)
563554

564555
def test_rjsmin(self):
565-
try:
566-
import rjsmin
567-
except ImportError:
568-
pytest.skip()
556+
rjsmin = pytest.importorskip('rjsmin')
569557
self.mkbundle('foo.js', filters='rjsmin', output='out.js').build()
570558
assert self.get('out.js') == 'function foo(bar){var dummy;document.write(bar);var a="\xc3\x9cn\xc3\xadc\xc3\xb4d\xc3\xa8";}'
571559

@@ -574,38 +562,29 @@ def test_jspacker(self):
574562
assert self.get('out.js').startswith('eval(function(p,a,c,k,e,d)')
575563

576564
def test_yui_js(self):
577-
try:
578-
import yuicompressor
579-
except ImportError:
580-
pytest.skip()
565+
yuicompressor = pytest.importorskip('yuicompressor')
581566
self.mkbundle('foo.js', filters='yui_js', output='out.js').build()
582567
assert self.get('out.js') == 'function foo(c){var d;document.write(c);var b="Ünícôdè"};'
583568

584569
def test_yui_css(self):
585-
try:
586-
import yuicompressor
587-
except ImportError:
588-
pytest.skip()
570+
yuicompressor = pytest.importorskip('yuicompressor')
589571
self.mkbundle('foo.css', filters='yui_css', output='out.css').build()
590572
assert self.get('out.css') == """h1{font-family:"Verdana";color:#fff}"""
591573

592574
def test_cleancss(self):
593575
if not find_executable('cleancss'):
594-
pytest.skip()
576+
pytest.skip('no cleancss')
595577
self.mkbundle('foo.css', filters='cleancss', output='out.css').build()
596578
assert self.get('out.css') in ('h1{font-family:Verdana;color:#FFF}', 'h1{font-family:Verdana;color:#fff}')
597579

598580
def test_cssslimmer(self):
599-
try:
600-
import slimmer
601-
except ImportError:
602-
pytest.skip()
581+
slimmer = pytest.importorskip('slimmer')
603582
self.mkbundle('foo.css', filters='css_slimmer', output='out.css').build()
604583
assert self.get('out.css') == 'h1{font-family:"Verdana";color:#FFF}'
605584

606585
def test_stylus(self):
607586
if not find_executable('stylus'):
608-
pytest.skip()
587+
pytest.skip('no stylus')
609588
self.create_files({'in': """a\n width:100px\n height:(@width/2)"""})
610589
self.mkbundle('in', filters='stylus', output='out.css').build()
611590
assert self.get('out.css') == """a {\n width: 100px;\n height: 50px;\n}\n\n"""
@@ -614,7 +593,7 @@ def test_rcssmin(self):
614593
try:
615594
self.mkbundle('foo.css', filters='rcssmin', output='out.css').build()
616595
except EnvironmentError:
617-
pytest.skip()
596+
pytest.skip('no rcssmin')
618597
assert self.get('out.css') == """h1{font-family:"Verdana";color:#FFFFFF}"""
619598

620599
def test_find_pyc_files( self ):
@@ -631,10 +610,7 @@ def test_find_packages( self ):
631610
class TestCSSPrefixer(TempEnvironmentHelper):
632611

633612
def setup(self):
634-
try:
635-
import cssprefixer
636-
except ImportError:
637-
pytest.skip()
613+
cssprefixer = pytest.importorskip('cssprefixer')
638614
TempEnvironmentHelper.setup(self)
639615

640616
def test(self):
@@ -652,7 +628,7 @@ class TestCoffeeScript(TempEnvironmentHelper):
652628

653629
def setup(self):
654630
if not find_executable('coffee'):
655-
pytest.skip()
631+
pytest.skip('no coffee')
656632
TempEnvironmentHelper.setup(self)
657633

658634
def test_default_options(self):
@@ -675,10 +651,7 @@ def test_bare_option(self):
675651
class TestJinja2(TempEnvironmentHelper):
676652

677653
def setup(self):
678-
try:
679-
import jinja2
680-
except ImportError:
681-
pytest.skip()
654+
jinja2 = pytest.importorskip('jinja')
682655
TempEnvironmentHelper.setup(self)
683656

684657
def test_default_options(self):
@@ -706,11 +679,7 @@ class TestClosure(TempEnvironmentHelper):
706679
}
707680

708681
def setup(self):
709-
try:
710-
import closure
711-
except ImportError:
712-
pytest.skip()
713-
682+
closure = pytest.importorskip('closure')
714683
TempEnvironmentHelper.setup(self)
715684

716685
def test_closure(self):
@@ -834,7 +803,7 @@ class TestLess(TempEnvironmentHelper):
834803

835804
def setup(self):
836805
if not find_executable('lessc'):
837-
pytest.skip()
806+
pytest.skip('no lessc')
838807
TempEnvironmentHelper.setup(self)
839808

840809
def test(self):
@@ -930,10 +899,10 @@ class TestRubySass(TempEnvironmentHelper):
930899

931900
def setup(self):
932901
if not find_executable('sass'):
933-
pytest.skip()
902+
pytest.skip('no sass')
934903

935904
if "Ruby" not in check_output(["sass", "--version"]).decode('utf-8'):
936-
pytest.skip()
905+
pytest.skip('no Ruby')
937906

938907
TempEnvironmentHelper.setup(self)
939908

@@ -1040,7 +1009,7 @@ class TestSass(TempEnvironmentHelper):
10401009

10411010
def setup(self):
10421011
if not find_executable('sass'):
1043-
pytest.skip()
1012+
pytest.skip('no sass')
10441013
TempEnvironmentHelper.setup(self)
10451014

10461015
def test_sass(self):
@@ -1104,7 +1073,7 @@ def setup(self):
11041073
import scss
11051074
self.scss = scss
11061075
except ImportError:
1107-
pytest.skip()
1076+
pytest.skip('no scss')
11081077
TempEnvironmentHelper.setup(self)
11091078

11101079
def test(self):
@@ -1119,7 +1088,7 @@ def test_assets(self):
11191088
from PIL import Image
11201089
Image.new('RGB', (10,10)).save(StringIO(), 'png')
11211090
except (ImportError, IOError):
1122-
pytest.skip()
1091+
pytest.skip('no PIL or Pillow')
11231092
self.create_files({'noise.scss': 'h1 {background: background-noise()}'})
11241093
self.mkbundle('noise.scss', filters='pyscss', output='out.css').build()
11251094

@@ -1141,7 +1110,7 @@ def setup(self):
11411110
import sass
11421111
self.sass = sass
11431112
except ImportError:
1144-
pytest.skip()
1113+
pytest.skip('no sass')
11451114
TempEnvironmentHelper.setup(self)
11461115

11471116
def test(self):
@@ -1200,7 +1169,7 @@ class TestCompass(TempEnvironmentHelper):
12001169

12011170
def setup(self):
12021171
if not find_executable('compass'):
1203-
pytest.skip()
1172+
pytest.skip('no compass')
12041173
TempEnvironmentHelper.setup(self)
12051174

12061175
def test_compass(self):
@@ -1426,7 +1395,7 @@ class TestHandlebars(TempEnvironmentHelper):
14261395

14271396
def setup(self):
14281397
if not find_executable('handlebars'):
1429-
pytest.skip()
1398+
pytest.skip('no handlebars')
14301399
TempEnvironmentHelper.setup(self)
14311400

14321401
def test_basic(self):
@@ -1462,10 +1431,7 @@ class TestJinja2JS(TempEnvironmentHelper):
14621431
}
14631432

14641433
def setup(self):
1465-
try:
1466-
import closure_soy
1467-
except:
1468-
pytest.skip()
1434+
closure_soy = pytest.importorskip('closure_soy')
14691435
TempEnvironmentHelper.setup(self)
14701436

14711437
def test(self):
@@ -1492,7 +1458,7 @@ class TestTypeScript(TempEnvironmentHelper):
14921458

14931459
def setup(self):
14941460
if not find_executable('tsc'):
1495-
pytest.skip()
1461+
pytest.skip('no tsc')
14961462
TempEnvironmentHelper.setup(self)
14971463

14981464
def test(self):
@@ -1575,7 +1541,7 @@ class TestClosureStylesheets(TempEnvironmentHelper):
15751541

15761542
def setup(self):
15771543
if not 'CLOSURE_STYLESHEETS_PATH' in os.environ:
1578-
pytest.skip()
1544+
pytest.skip('no CLOSURE_STYLESHEETS_PATH in env')
15791545
TempEnvironmentHelper.setup(self)
15801546

15811547
def test_compiler(self):
@@ -1602,7 +1568,7 @@ def test_first(self):
16021568
except FilterError as e:
16031569
# postcss is not installed, that's ok.
16041570
if 'Program file not found' in e.message:
1605-
pytest.skip()
1571+
pytest.skip(e.message)
16061572
else:
16071573
raise
16081574
out = self.get('output.css')
@@ -1621,7 +1587,7 @@ def test_es2015(self):
16211587
except FilterError as e:
16221588
# babel is not installed, that's ok.
16231589
if 'Program file not found' in str(e):
1624-
pytest.skip()
1590+
pytest.skip(e.message)
16251591
else:
16261592
raise
16271593
assert "var x = function x" in self.get('output.js')
@@ -1633,7 +1599,7 @@ def test_extra_args(self):
16331599
except FilterError as e:
16341600
# babel is not installed, that's ok.
16351601
if 'Program file not found' in e.message:
1636-
pytest.skip()
1602+
pytest.skip(e.message)
16371603
else:
16381604
raise
16391605
assert (self.get('output.js').strip() ==

0 commit comments

Comments
 (0)