因為 import 問題而無法殺死突變¶
針對使用不同名稱載入模組會讓突變存活下來的範例。在這個案例中,問題跟 Cosmic-Ray 如何載入突變模組有關。這已經在 PR #158 中修復。
Reproducer¶
$ pip install https://github.com/sixty-north/cosmic-ray/zipball/2a48656
$ celery -A cosmic_ray.tasks.worker worker
$ cosmic-ray run --baseline=10 example.json sandwich/ham/ham.py -- tests
$ cosmic-ray report example.json
job ID 1:Outcome.SURVIVED:sandwich.ham.ham
command: cosmic-ray worker sandwich.ham.ham number_replacer 0 unittest -- tests
--- mutation diff ---
--- a/sandwich/ham/ham.py
+++ b/sandwich/ham/ham.py
@@ -3,6 +3,6 @@
class Ham(object):
- def __init__(self, pieces=10):
+ def __init__(self, pieces=11):
self.pieces = pieces
total jobs: 1
complete: 1 (100.00%)
survival rate: 100.00%
備註
在這個範例中 test_control.py
在修復後便能正確殺死突變。
程式碼¶
class Ham(object):
def __init__(self, pieces=10):
self.pieces = pieces
from sandwich.ham import ham
ham_class = ham.Ham
import sandwich.control
import unittest
class TestControl(unittest.TestCase):
def test_loading_via_importlib(self):
ham_in_fridge = sandwich.control.ham_class()
self.assertEqual(ham_in_fridge.pieces, 10)
if __name__ == "__main__":
unittest.main()