Last active
December 15, 2015 20:28
-
-
Save ReSTARTR/5318360 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
class Hoge(object): | |
def __init__(self, v): | |
self.val = v | |
def update(self, v): | |
self.val = v |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ python ./test_hoge_pytest.py -v | |
================================ test session starts ================================ | |
platform darwin -- Python 2.7.3 -- pytest-2.3.4 -- /Users/yoshida/.pyenv/versions/pyenv27/bin/python | |
collected 4 items | |
test_hoge_pytest.py:10: TestHoge1.test_type PASSED | |
test_hoge_pytest.py:13: TestHoge1.test_val FAILED | |
test_hoge_unittest.py:10: TestHoge1.test_type PASSED | |
test_hoge_unittest.py:13: TestHoge1.test_val FAILED | |
===================================== FAILURES ====================================== | |
________________________________ TestHoge1.test_val _________________________________ | |
self = <test_hoge_pytest.TestHoge1 object at 0x1016ca650> | |
hoge = <hoge.Hoge object at 0x1016ca750> | |
def test_val(self, hoge): | |
assert hoge.val == 1 | |
hoge.update(2) | |
> assert hoge.val == 1 | |
E assert 2 == 1 | |
E + where 2 = <hoge.Hoge object at 0x1016ca750>.val | |
test_hoge_pytest.py:17: AssertionError | |
________________________________ TestHoge1.test_val _________________________________ | |
self = <test_hoge_unittest.TestHoge1 testMethod=test_val> | |
def test_val(self): | |
self.assertEqual(self.hoge.val, 1) | |
self.hoge.update(2) | |
> self.assertEqual(self.hoge.val, 1) | |
E AssertionError: 2 != 1 | |
test_hoge_unittest.py:17: AssertionError | |
======================== 2 failed, 2 passed in 0.13 seconds ========================= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ python ./test_hoge_pytest.py -v | |
================================ test session starts ================================ | |
platform darwin -- Python 2.7.3 -- pytest-2.3.4 -- /Users/yoshida/.pyenv/versions/pyenv27/bin/python | |
collected 4 items | |
test_hoge_pytest.py:10: TestHoge1.test_type PASSED | |
test_hoge_pytest.py:13: TestHoge1.test_val PASSED | |
test_hoge_unittest.py:10: TestHoge1.test_type PASSED | |
test_hoge_unittest.py:13: TestHoge1.test_val PASSED | |
============================= 4 passed in 0.04 seconds ============================== |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ python ./test_hoge_unittest.py -v | |
test_type (__main__.TestHoge1) ... ok | |
test_val (__main__.TestHoge1) ... ok | |
---------------------------------------------------------------------- | |
Ran 2 tests in 0.000s | |
OK |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ python ./test_hoge_unittest.py -v | |
test_type (__main__.TestHoge1) ... ok | |
test_val (__main__.TestHoge1) ... FAIL | |
====================================================================== | |
FAIL: test_val (__main__.TestHoge1) | |
---------------------------------------------------------------------- | |
Traceback (most recent call last): | |
File "./test_hoge_unittest.py", line 17, in test_val | |
self.assertEqual(self.hoge.val, 1) | |
AssertionError: 2 != 1 | |
---------------------------------------------------------------------- | |
Ran 2 tests in 0.000s | |
FAILED (failures=1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
from hoge import Hoge | |
import pytest | |
class TestHoge1(object): | |
def pytest_funcarg__hoge(request): | |
return Hoge(1) | |
def test_type(self, hoge): | |
assert isinstance(hoge, Hoge) | |
def test_val(self, hoge): | |
assert hoge.val == 1 | |
hoge.update(2) | |
assert hoge.val == 2 | |
if __name__ == '__main__': | |
pytest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
from hoge import Hoge | |
import unittest | |
class TestHoge1(unittest.TestCase): | |
def setUp(self): | |
self.hoge = Hoge(1) | |
def test_type(self): | |
self.assertIsInstance(self.hoge, Hoge) | |
def test_val(self): | |
self.assertEqual(self.hoge.val, 1) | |
self.hoge.update(2) | |
self.assertEqual(self.hoge.val, 2) | |
if __name__ == '__main__': | |
unittest.main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment