Skip to content

Commit 4a748cc

Browse files
gfyoungjreback
authored andcommitted
MAINT: Complete Conversion to Pytest Idiom (pandas-dev#16201)
* MAINT: Convert test setup/teardown to pytest idiom * tm.TestCase now just inherits from object * setUpClass renamed to setup_class * tearDownClass renamed to teardown_class * setUp renamed to setup_method * tearDown renamed to teardown_method * MAINT: Remove unittest.TestCase from testing * DOC: Update documentation for TestCase usage tm.TestCase no longer follows the nosetest idiom, so it is here to stay, so update the documentation to say that we are using it still. Closes pandas-devgh-15990. * TST: Patch Circle matplotlib failure The tm.mplskip decorator was breaking on Circle, so this commit removes the decorator and replaces it with direct function calls to check for matplotlib. * TST: Replace yield-based tests in test_query_eval
1 parent 1002cc3 commit 4a748cc

File tree

109 files changed

+374
-440
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

109 files changed

+374
-440
lines changed

doc/source/contributing.rst

-8
Original file line numberDiff line numberDiff line change
@@ -632,14 +632,6 @@ framework that will facilitate testing and developing. Thus, instead of writing
632632
def test_really_cool_feature():
633633
....
634634
635-
Sometimes, it does make sense to bundle test functions together into a single class, either because the test file is testing multiple functions from a single module, and
636-
using test classes allows for better organization. However, instead of inheriting from ``tm.TestCase``, we should just inherit from ``object``:
637-
638-
.. code-block:: python
639-
640-
class TestReallyCoolFeature(object):
641-
....
642-
643635
Using ``pytest``
644636
~~~~~~~~~~~~~~~~
645637

pandas/tests/computation/test_eval.py

+31-31
Original file line numberDiff line numberDiff line change
@@ -98,17 +98,17 @@ def _is_py3_complex_incompat(result, expected):
9898
class TestEvalNumexprPandas(tm.TestCase):
9999

100100
@classmethod
101-
def setUpClass(cls):
102-
super(TestEvalNumexprPandas, cls).setUpClass()
101+
def setup_class(cls):
102+
super(TestEvalNumexprPandas, cls).setup_class()
103103
tm.skip_if_no_ne()
104104
import numexpr as ne
105105
cls.ne = ne
106106
cls.engine = 'numexpr'
107107
cls.parser = 'pandas'
108108

109109
@classmethod
110-
def tearDownClass(cls):
111-
super(TestEvalNumexprPandas, cls).tearDownClass()
110+
def teardown_class(cls):
111+
super(TestEvalNumexprPandas, cls).teardown_class()
112112
del cls.engine, cls.parser
113113
if hasattr(cls, 'ne'):
114114
del cls.ne
@@ -137,12 +137,12 @@ def setup_ops(self):
137137
self.arith_ops = _good_arith_ops
138138
self.unary_ops = '-', '~', 'not '
139139

140-
def setUp(self):
140+
def setup_method(self, method):
141141
self.setup_ops()
142142
self.setup_data()
143143
self.current_engines = filter(lambda x: x != self.engine, _engines)
144144

145-
def tearDown(self):
145+
def teardown_method(self, method):
146146
del self.lhses, self.rhses, self.scalar_rhses, self.scalar_lhses
147147
del self.pandas_rhses, self.pandas_lhses, self.current_engines
148148

@@ -723,8 +723,8 @@ def test_float_truncation(self):
723723
class TestEvalNumexprPython(TestEvalNumexprPandas):
724724

725725
@classmethod
726-
def setUpClass(cls):
727-
super(TestEvalNumexprPython, cls).setUpClass()
726+
def setup_class(cls):
727+
super(TestEvalNumexprPython, cls).setup_class()
728728
tm.skip_if_no_ne()
729729
import numexpr as ne
730730
cls.ne = ne
@@ -750,8 +750,8 @@ def check_chained_cmp_op(self, lhs, cmp1, mid, cmp2, rhs):
750750
class TestEvalPythonPython(TestEvalNumexprPython):
751751

752752
@classmethod
753-
def setUpClass(cls):
754-
super(TestEvalPythonPython, cls).setUpClass()
753+
def setup_class(cls):
754+
super(TestEvalPythonPython, cls).setup_class()
755755
cls.engine = 'python'
756756
cls.parser = 'python'
757757

@@ -780,8 +780,8 @@ def check_alignment(self, result, nlhs, ghs, op):
780780
class TestEvalPythonPandas(TestEvalPythonPython):
781781

782782
@classmethod
783-
def setUpClass(cls):
784-
super(TestEvalPythonPandas, cls).setUpClass()
783+
def setup_class(cls):
784+
super(TestEvalPythonPandas, cls).setup_class()
785785
cls.engine = 'python'
786786
cls.parser = 'pandas'
787787

@@ -1070,16 +1070,16 @@ def test_performance_warning_for_poor_alignment(self, engine, parser):
10701070
class TestOperationsNumExprPandas(tm.TestCase):
10711071

10721072
@classmethod
1073-
def setUpClass(cls):
1074-
super(TestOperationsNumExprPandas, cls).setUpClass()
1073+
def setup_class(cls):
1074+
super(TestOperationsNumExprPandas, cls).setup_class()
10751075
tm.skip_if_no_ne()
10761076
cls.engine = 'numexpr'
10771077
cls.parser = 'pandas'
10781078
cls.arith_ops = expr._arith_ops_syms + expr._cmp_ops_syms
10791079

10801080
@classmethod
1081-
def tearDownClass(cls):
1082-
super(TestOperationsNumExprPandas, cls).tearDownClass()
1081+
def teardown_class(cls):
1082+
super(TestOperationsNumExprPandas, cls).teardown_class()
10831083
del cls.engine, cls.parser
10841084

10851085
def eval(self, *args, **kwargs):
@@ -1492,8 +1492,8 @@ def test_simple_in_ops(self):
14921492
class TestOperationsNumExprPython(TestOperationsNumExprPandas):
14931493

14941494
@classmethod
1495-
def setUpClass(cls):
1496-
super(TestOperationsNumExprPython, cls).setUpClass()
1495+
def setup_class(cls):
1496+
super(TestOperationsNumExprPython, cls).setup_class()
14971497
cls.engine = 'numexpr'
14981498
cls.parser = 'python'
14991499
tm.skip_if_no_ne(cls.engine)
@@ -1566,8 +1566,8 @@ def test_simple_bool_ops(self):
15661566
class TestOperationsPythonPython(TestOperationsNumExprPython):
15671567

15681568
@classmethod
1569-
def setUpClass(cls):
1570-
super(TestOperationsPythonPython, cls).setUpClass()
1569+
def setup_class(cls):
1570+
super(TestOperationsPythonPython, cls).setup_class()
15711571
cls.engine = cls.parser = 'python'
15721572
cls.arith_ops = expr._arith_ops_syms + expr._cmp_ops_syms
15731573
cls.arith_ops = filter(lambda x: x not in ('in', 'not in'),
@@ -1577,8 +1577,8 @@ def setUpClass(cls):
15771577
class TestOperationsPythonPandas(TestOperationsNumExprPandas):
15781578

15791579
@classmethod
1580-
def setUpClass(cls):
1581-
super(TestOperationsPythonPandas, cls).setUpClass()
1580+
def setup_class(cls):
1581+
super(TestOperationsPythonPandas, cls).setup_class()
15821582
cls.engine = 'python'
15831583
cls.parser = 'pandas'
15841584
cls.arith_ops = expr._arith_ops_syms + expr._cmp_ops_syms
@@ -1587,16 +1587,16 @@ def setUpClass(cls):
15871587
class TestMathPythonPython(tm.TestCase):
15881588

15891589
@classmethod
1590-
def setUpClass(cls):
1591-
super(TestMathPythonPython, cls).setUpClass()
1590+
def setup_class(cls):
1591+
super(TestMathPythonPython, cls).setup_class()
15921592
tm.skip_if_no_ne()
15931593
cls.engine = 'python'
15941594
cls.parser = 'pandas'
15951595
cls.unary_fns = _unary_math_ops
15961596
cls.binary_fns = _binary_math_ops
15971597

15981598
@classmethod
1599-
def tearDownClass(cls):
1599+
def teardown_class(cls):
16001600
del cls.engine, cls.parser
16011601

16021602
def eval(self, *args, **kwargs):
@@ -1694,26 +1694,26 @@ def test_keyword_arg(self):
16941694
class TestMathPythonPandas(TestMathPythonPython):
16951695

16961696
@classmethod
1697-
def setUpClass(cls):
1698-
super(TestMathPythonPandas, cls).setUpClass()
1697+
def setup_class(cls):
1698+
super(TestMathPythonPandas, cls).setup_class()
16991699
cls.engine = 'python'
17001700
cls.parser = 'pandas'
17011701

17021702

17031703
class TestMathNumExprPandas(TestMathPythonPython):
17041704

17051705
@classmethod
1706-
def setUpClass(cls):
1707-
super(TestMathNumExprPandas, cls).setUpClass()
1706+
def setup_class(cls):
1707+
super(TestMathNumExprPandas, cls).setup_class()
17081708
cls.engine = 'numexpr'
17091709
cls.parser = 'pandas'
17101710

17111711

17121712
class TestMathNumExprPython(TestMathPythonPython):
17131713

17141714
@classmethod
1715-
def setUpClass(cls):
1716-
super(TestMathNumExprPython, cls).setUpClass()
1715+
def setup_class(cls):
1716+
super(TestMathNumExprPython, cls).setup_class()
17171717
cls.engine = 'numexpr'
17181718
cls.parser = 'python'
17191719

pandas/tests/frame/test_asof.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111

1212
class TestFrameAsof(TestData, tm.TestCase):
13-
def setUp(self):
13+
def setup_method(self, method):
1414
self.N = N = 50
1515
self.rng = date_range('1/1/1990', periods=N, freq='53s')
1616
self.df = DataFrame({'A': np.arange(N), 'B': np.arange(N)},

pandas/tests/frame/test_indexing.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -2914,7 +2914,7 @@ def test_type_error_multiindex(self):
29142914

29152915
class TestDataFrameIndexingDatetimeWithTZ(tm.TestCase, TestData):
29162916

2917-
def setUp(self):
2917+
def setup_method(self, method):
29182918
self.idx = Index(date_range('20130101', periods=3, tz='US/Eastern'),
29192919
name='foo')
29202920
self.dr = date_range('20130110', periods=3)
@@ -2972,7 +2972,7 @@ def test_transpose(self):
29722972

29732973
class TestDataFrameIndexingUInt64(tm.TestCase, TestData):
29742974

2975-
def setUp(self):
2975+
def setup_method(self, method):
29762976
self.ir = Index(np.arange(3), dtype=np.uint64)
29772977
self.idx = Index([2**63, 2**63 + 5, 2**63 + 10], name='foo')
29782978

pandas/tests/frame/test_period.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def _permute(obj):
1414

1515
class TestPeriodIndex(tm.TestCase):
1616

17-
def setUp(self):
17+
def setup_method(self, method):
1818
pass
1919

2020
def test_as_frame_columns(self):

0 commit comments

Comments
 (0)