Skip to content

Commit

Permalink
Make test runnable from command line.
Browse files Browse the repository at this point in the history
`pytest tests` works now. I can't explain why `pytest` alone does not,
but it could have something to do with us not being a real Python
package.

With just `pytest` I get:

    E   ModuleNotFoundError: No module named 'tests.test_factions'

But `python -c "import tests.test_factions"` works fine.
  • Loading branch information
DanAlbert committed Oct 30, 2020
1 parent f365487 commit 258c34e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
Empty file added tests/__init__.py
Empty file.
9 changes: 7 additions & 2 deletions tests/test_factions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json
from pathlib import Path
import unittest

from dcs.helicopters import UH_1H, AH_64A
Expand All @@ -11,13 +12,17 @@
from game.factions.faction import Faction


THIS_DIR = Path(__file__).parent
RESOURCES_DIR = THIS_DIR / "resources"


class TestFactionLoader(unittest.TestCase):

def setUp(self):
pass

def test_load_valid_faction(self):
with open("./resources/valid_faction.json", 'r') as data:
with (RESOURCES_DIR / "valid_faction.json").open('r') as data:
faction = Faction.from_json(json.load(data))

self.assertEqual(faction.country, "USA")
Expand Down Expand Up @@ -87,7 +92,7 @@ def test_load_valid_faction(self):

def test_load_valid_faction_with_invalid_country(self):

with open("./resources/invalid_faction_country.json", 'r') as data:
with (RESOURCES_DIR / "invalid_faction_country.json").open("r") as data:
try:
Faction.from_json(json.load(data))
self.fail("Should have thrown assertion error")
Expand Down

0 comments on commit 258c34e

Please sign in to comment.