SoCo项目有一个小型测试套件,其中一个测试仅在第一次运行时在pypy下失败(当不存在 pyc 文件时)。后续运行成功。
第一次运行测试时,失败测试的输出是
E assert {'CurrentLEDS...': 'μИⅠℂ☺ΔЄ'} == {'CurrentLEDSt...: 'μИⅠℂ☺ΔЄ'}
E Common items:
E {'CurrentLEDState': 'On'}
E Differing items:
E {'Unicode': 'μИⅠℂ☺ΔЄ'} != {'Unicode': 'μИⅠℂ☺ΔЄ'}
请注意,在“不同项目”中,双方完全相等。测试运行会创建一个unittest/__pycache__/test_services.pypy-20-PYTEST.pyc
文件。在保持文件完整的情况下运行测试时,它会成功。删除pyc文件并再次运行测试时,失败。
失败的测试可以重现(假设你安装了 pypy)
mkdir soco-tmp
cd soco-tmp/
git clone https://github.com/SoCo/SoCo.git
cd SoCo/
git reset --hard 4d6cea18d30e5b30ed5c6f #that's the current revision when writing this
virtualenv -p `which pypy` venv
source venv/bin/activate
python --version
# Python 2.7.3 (2.2.1+dfsg-1~ppa1, Nov 28 2013, 02:02:56)
# [PyPy 2.2.1 with GCC 4.6.3]
pip install -r requirements.txt -r requirements-dev.txt
pip install .
py.test unittest/test_services.py # should fail
py.test unittest/test_services.py # should succeed
rm unittest/__pycache__/*
python -B -mpytest unittest/test_services.py # will always fail as no pyc is created
这似乎是 PyPy 中的一个错误,但是到目前为止我无法在一个简单的测试用例中重现它......
有任何想法吗?