简体   繁体   English

单元测试未运行

[英]Unit Tests not Running

I'm making a game study in python and I couldn't get unit tests running. 我正在使用python进行游戏研究,但无法运行单元测试。 It seems packages might be wrong, I'm not sure. 不确定包装可能是错误的,我不确定。

My folder structure is the following: 我的文件夹结构如下:

folder/
    src/
      __init__.py
      scenario.py
      monster.py
      ...
    tests/
      __init__.py
      testmonster.py

I'm at 'folder' running the following command 我在“文件夹”中运行以下命令

python -m tests.testmonster.py

This is my test class 这是我的考试课

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()

When I try to run the file I get 当我尝试运行文件时,我得到

Ran 0 tests in 0.000s

Am I missing something ? 我想念什么吗? Is it about the path ? 关于路径吗? I dindt wish to use VM`s 我不想使用虚拟机

I simulated your setup and was able to repeat what you see. 我模拟了您的设置,并能够重复您看到的内容。 However, if I enter the test folder and drop the '-m', it then works fine for me. 但是,如果我进入测试文件夹并放下'-m',则对我来说效果很好。

python testmonster.py

Ran 1 test in 0.000s 在0.000秒内进行1次测试

Also, I recommend assertpy; 另外,我建议使用assertpy; github , I find it more readable than assertions with the standard library. github ,我发现它比标准库的断言更具可读性。

SteveJ SteveJ

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM