I have established below simple test snippet out of the project:
import sys
import unittest
def sizeof(data):
if isinstance(data, int):
bit_length = len(bin(data)[2:])
return bit_length // 8 + (1 if bit_length % 8 else 0)
return sys.getsizeof(data) - sys.getsizeof(data.__class__())
class UnitTestHelper(unittest.TestCase):
def test_sizeof(self):
self.assertEqual(sizeof(1), 1, "size for - {} must be 1 byte!".format(1))
self.assertEqual(sizeof((2 ** (8 * 40)) - 1), 40, "size for - {} must be 40 bytes!".format((2 ** (8 * 40)) - 1))
for i in range(10, 200):
val = 2**(8*i) - 1
self.assertEqual(sizeof(val), i, "size for - {} must be {} bytes!!".format(val, i))
self.assertEqual(sizeof("question"), len("question"), "size mismatch!!!")
If I run above program as Run mechanism in Pycharm (with Pytest) I get the result as:
Launching pytest with arguments MyTest.py::UnitTestHelper::test_sizeof --no-header --no-summary -q in C:\Test
============================= test session starts =============================
collecting ... collected 1 item
MyTest.py::UnitTestHelper::test_sizeof PASSED [100%]
======================== 1 passed, 1 warning in 0.02s =========================
Launching pytest with arguments MyTest.py::UnitTestHelper::test_sizeof --no-header --no-summary -q in C:\Test
============================= test session starts =============================
collecting ... collected 1 item
MyTest.py::UnitTestHelper::test_sizeof FAILED [100%]
size mismatch!!!
8 != 6
Expected :6
Actual :8
<Click to see difference>
self = <MyTest.UnitTestHelper testMethod=test_sizeof>
def test_sizeof(self):
self.assertEqual(sizeof(1), 1, "size for - {} must be 1 byte!".format(1))
self.assertEqual(sizeof((2 ** (8 * 40)) - 1), 40, "size for - {} must be 40 bytes!".format((2 ** (8 * 40)) - 1))
for i in range(10, 200):
val = 2**(8*i) - 1
self.assertEqual(sizeof(val), i, "size for - {} must be {} bytes!!".format(val, i))
> self.assertEqual(sizeof("question"), len("question"), "size mismatch!!!")
MyTest.py:20: AssertionError
======================== 1 failed, 1 warning in 0.64s =========================
Same failure result I noticed with jetbrains Teamcity Pytest configuration as well.
What could be the possible reason for such inconsistency of class variables?