From 06a6d9ceb60f9b2179b0be23c0e95371f834733b Mon Sep 17 00:00:00 2001 From: Oliver Hamlet Date: Mon, 25 Mar 2019 08:38:07 +0000 Subject: [PATCH] Use CTest to run Python tests Avoid having to copy the test script by modifying PYTHONPATH at runtime, and move the test script into the test directory. --- CMakeLists.txt | 10 +++++----- {src => test}/test.py | 7 ++++++- 2 files changed, 11 insertions(+), 6 deletions(-) rename {src => test}/test.py (96%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3f6bd31..59b16d3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -106,11 +106,11 @@ add_custom_command(TARGET loot_api POST_BUILD "${LIBLOOT_EXTRACTED_PATH}/${LIBLOOT_SHARED_LIBRARY}" "$/${LIBLOOT_SHARED_LIBRARY}") -# Copy the test Python script to the build directory. -add_custom_command(TARGET loot_api POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy_if_different - "${CMAKE_SOURCE_DIR}/src/test.py" - "$/test.py") +enable_testing() + +add_test(NAME python + WORKING_DIRECTORY $ + COMMAND "${PYTHON_EXECUTABLE}" ${CMAKE_SOURCE_DIR}/test/test.py) ######################################## # Install diff --git a/src/test.py b/test/test.py similarity index 96% rename from src/test.py rename to test/test.py index a9f3f65..a50a93f 100644 --- a/src/test.py +++ b/test/test.py @@ -1,9 +1,14 @@ #!/usr/bin/env python import cProfile +import os import os.path import shutil +import sys import unittest + +sys.path.append(os.getcwd()) + from loot_api import Version from loot_api import WrapperVersion from loot_api import GameType @@ -63,7 +68,7 @@ class TestLootApi(GameFixture): self.assertNotEqual(db, None) class TestDatabaseInterface(GameFixture): - masterlist_path = u'../../test/masterlist.yaml' + masterlist_path = os.path.join(os.path.dirname(__file__), u'masterlist.yaml') def setUp(self): super(TestDatabaseInterface, self).setUp()