[英]Unit Tests not Running
我正在使用python進行游戲研究,但無法運行單元測試。 不確定包裝可能是錯誤的,我不確定。
我的文件夾結構如下:
folder/
src/
__init__.py
scenario.py
monster.py
...
tests/
__init__.py
testmonster.py
我在“文件夾”中運行以下命令
python -m tests.testmonster.py
這是我的考試課
import unittest
from src.scenario import Scene
from src.monster import Zombie
import sys
class TestMonster(unittest.TestCase):
scene = None
def setUp(self):
scene = Scene()
def testHit(self):
zombie = Zombie(self.scene, 0,0)
# we got 1 zombie now
assertEqual(len(scene.zombies), 1)
damage = scene.getPlayer().gun.damage
zombielife = zombie.hp
numberOfHits = zombielife / damage
print numberOfHits
unittest.main()
當我嘗試運行文件時,我得到
Ran 0 tests in 0.000s
我想念什么嗎? 關於路徑嗎? 我不想使用虛擬機
我模擬了您的設置,並能夠重復您看到的內容。 但是,如果我進入測試文件夾並放下'-m',則對我來說效果很好。
python testmonster.py
在0.000秒內進行1次測試
另外,我建議使用assertpy; github ,我發現它比標准庫的斷言更具可讀性。
SteveJ
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.