0

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

asked Nov 21, 2017 at 21:41
5
  • 1
    Have you tried self.asserting something? ie self.assertEqual(numberOfHits, 3) Commented Nov 21, 2017 at 21:43
  • Yeah =( Didn't work as well Commented Nov 21, 2017 at 21:55
  • why are you running it as -m just skip that Commented Nov 21, 2017 at 21:56
  • I believe you need to be in your 'tests' folder. Commented Nov 21, 2017 at 21:58
  • This first thing I would do is put something like print '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. Commented Nov 21, 2017 at 22:13

1 Answer 1

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

answered Nov 21, 2017 at 22:07
Sign up to request clarification or add additional context in comments.

8 Comments

Wow, so im missing the packages, maybe something i've missed. I get a "No module named src.scenario" when i do the run you do
Why is assertpy better?
@user1767754; readability, eg; "assert_that(1 + 2).is_equal_to(3)". I should have stated that clearly, I'll edit my post.
@GabrielSlomka; This is another question - but may I offer something that will save you a lot of work in the future. Invest the time to learn virtualenv, and virtualenvwrapper (if you are not already using it). Then go to the top level project folder (the one above 'folder' in your case), and run the command "add2virtualenv <folder>". I fought this problem long and hard until I learned the above : )
i've tryed the above method, "No module named src.scenario".
|

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.