test_unittest.py 文件源码

python
阅读 24 收藏 0 点赞 0 评论 0

项目:GSM-scanner 作者: yosriayed 项目源码 文件源码
def test_setup_setUpClass(testdir):
    testpath = testdir.makepyfile("""
        import unittest
        import pytest
        class MyTestCase(unittest.TestCase):
            x = 0
            @classmethod
            def setUpClass(cls):
                cls.x += 1
            def test_func1(self):
                assert self.x == 1
            def test_func2(self):
                assert self.x == 1
            @classmethod
            def tearDownClass(cls):
                cls.x -= 1
        def test_teareddown():
            assert MyTestCase.x == 0
    """)
    reprec = testdir.inline_run(testpath)
    reprec.assertoutcome(passed=3)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号