Make test runnable from command line.

`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.
This commit is contained in:
Dan Albert 2020-10-30 15:05:44 -07:00
parent f365487fd6
commit 258c34e61d
2 changed files with 7 additions and 2 deletions

0
tests/__init__.py Normal file
View File

View File

@ -1,4 +1,5 @@
import json
from pathlib import Path
import unittest
from dcs.helicopters import UH_1H, AH_64A
@ -11,13 +12,17 @@ from dcs.vehicles import Armor, Unarmed, Infantry, Artillery
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")
@ -87,7 +92,7 @@ class TestFactionLoader(unittest.TestCase):
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")