I'm making a game study in python and I couldn't get unit tests running. 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
1 Answer 1
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.
python testmonster.py
Ran 1 test in 0.000s
Also, I recommend assertpy; github, I find it more readable than assertions with the standard library.
SteveJ
self.asserting something? ieself.assertEqual(numberOfHits, 3)-mjust skip thatprint 'running'at the top of the file, and if that prints, move inside the class and then method to see what executes and what does not.