나는 c- 확장명을 작성하고 pytest에서 테스트하고 싶다.파이썬 참조 카운트 c- 확장을 디버그하기 위해 계산
내가 테스트중인 부분은 참조 수가 내 개체에서 올바른지 여부입니다.
In [1]: x = 153513514215
In [2]: import sys
In [3]: sys.getrefcount(x)
Out[3]: 2
그래서 호출자에서 너무 좋아, 한 할당에서 참조 및 1 운임 : 그래서 나는 나 퍼즐 순수 파이썬의 작은 테스트 ... Ipython에서
내가 얻을 구축 할 수 있습니다. 나는 정상적인 파이썬 스크립트
$ python3 stackoverflow_test.py
x refcount = 4
y refcount = 4
왜 4가 아닌 2로 실행할 때 다음 스크립트 (stackoverflow_test.py는) 다음과 같은 결과
import sys
def test_ref_count_int():
x = 677461248192962146784178
assert sys.getrefcount(x) == 2
def test_ref_count_str():
y = 'very long and probbably very unique string'
assert sys.getrefcount(y) == 2
def normal_te_st():
x = 222677461248192962146784178
y = '!!!!very long and probbably unique string!!!!'
print ('x refcount = {}'.format(sys.getrefcount(x)))
print ('y refcount = {}'.format(sys.getrefcount(y)))
if __name__ == '__main__':
normal_te_st()
을 제공하지만
?
내가
$ python3 -m pytest stackoverflow_test.py
=================== test session starts ===================
platform linux -- Python 3.4.3, pytest-3.0.7, py-1.4.33, pluggy-0.4.0
rootdir: /opt/projects/0001_Intomics/00005_TextMining/jcr/textmining/tests, inifile:
collected 2 items
stackoverflow_test.py FF
======================== FAILURES =========================
___________________ test_ref_count_int ____________________
def test_ref_count_int():
x = 677461248192962146784178
> assert sys.getrefcount(x) == 2
E assert 3 == 2
E + where 3 = <built-in function getrefcount>(677461248192962146784178)
E + where <built-in function getrefcount> = sys.getrefcount
stackoverflow_test.py:7: AssertionError
___________________ test_ref_count_str ____________________
def test_ref_count_str():
y = 'very long and probbably very unique string'
> assert sys.getrefcount(y) == 2
E AssertionError: assert 3 == 2
E + where 3 = <built-in function getrefcount>('very long and probbably very unique string')
E + where <built-in function getrefcount> = sys.getrefcount
stackoverflow_test.py:11: AssertionError
왜 3이 아닌 2 pytest
으로 실행?질문 : 그
- 파이썬 = 4 심판 오는 방법
- pytest = 3 심판
- ipython 세션 = 2 심판 I가 그것을 기대
카운트 카운트 카운트 모든 3 가지 경우에 ipython에서와 같이 작동합니다. 아무도 무슨 일이 일어나는지 설명하고, 내가 만드는 객체를 테스트하는 방법을 알려줍니다.
참고 자료를 보내 주셔서 감사합니다.하지만이 답변은 내가 원하는 것입니다. – jcr