File tree Expand file tree Collapse file tree 2 files changed +21
-5
lines changed
Expand file tree Collapse file tree 2 files changed +21
-5
lines changed Original file line number Diff line number Diff line change 11import unittest
22
3- from stock_alerter .tests import test_stock
3+
4+ class AttribLoader (unittest .TestLoader ):
5+ def __init__ (self , attrib ):
6+ self .attrib = attrib
7+
8+ def loadTestsFromModule (self , module , use_load_tests = False ):
9+ return super ().loadTestsFromModule (module , use_load_tests = False )
10+
11+ def getTestCaseNames (self , testCaseClass ):
12+ test_names = super ().getTestCaseNames (testCaseClass )
13+ filtered_test_names = [test
14+ for test in test_names
15+ if hasattr (getattr (testCaseClass , test ),
16+ self .attrib )]
17+ return filtered_test_names
18+
419
520if __name__ == "__main__" :
21+ loader = AttribLoader ("slow" )
22+ test_suite = loader .discover ("." )
623 runner = unittest .TextTestRunner ()
7- runner .run (test_stock . suite () )
24+ runner .run (test_suite )
Original file line number Diff line number Diff line change 1- import sys
21import unittest
32import collections
43from datetime import datetime , timedelta
@@ -13,7 +12,6 @@ def setUp(self):
1312 def test_price_of_a_new_stock_class_should_be_None (self ):
1413 self .assertIsNone (self .goog .price )
1514
16- @unittest .skipIf (sys .platform .startswith ("win" ), "skip on windows" )
1715 def test_stock_update (self ):
1816 """An update should set the price on the stock object
1917
@@ -22,7 +20,8 @@ def test_stock_update(self):
2220 self .goog .update (datetime (2014 , 2 , 12 ), price = 10 )
2321 self .assertEqual (10 , self .goog .price )
2422
25- @unittest .skipUnless (sys .platform .startswith ("win" ), "only run on windows" )
23+ test_stock_update .slow = True
24+
2625 def test_negative_price_should_throw_ValueError (self ):
2726 with self .assertRaises (ValueError ):
2827 self .goog .update (datetime (2014 , 2 , 13 ), - 1 )
You can’t perform that action at this time.
0 commit comments