From 258c34e61d00f790c7f2838b3c5424656edaf215 Mon Sep 17 00:00:00 2001 From: Dan Albert Date: Fri, 30 Oct 2020 15:05:44 -0700 Subject: [PATCH] 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. --- tests/__init__.py | 0 tests/test_factions.py | 9 +++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) create mode 100644 tests/__init__.py diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/test_factions.py b/tests/test_factions.py index ecd32533..c5de3e94 100644 --- a/tests/test_factions.py +++ b/tests/test_factions.py @@ -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")