diff --git a/.travis.yml b/.travis.yml index a85894a..9635dac 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,6 +2,13 @@ language: python python: - "3.8" # commands to install dependencies + +before_install: #this is only for UnitTesterSG. + #For UnitTesterSG, we remove the test_13.py before running the runPytestDriver.py since that python file is designed to give an error as downloaded. + - cd test13 + - rm test_13.py + - cd .. + install: #No installation is required for UnitTesterSG with what is already on the Travis CI, so commenting out the below to let the build test run faster. #- virtualenv -p /opt/pyenv/versions/3.8/bin/python3.8 venv @@ -9,9 +16,6 @@ install: #- pip install UnitTesterSG[COMPLETE] #this is mostly to get the dependencies. #- python setup.py install #now overwrite old installations with the current version. # command to run tests -#remove the test_13.py before running the runPytestDriver.py since that python file is designed to give an error as downloaded. + script: - - cd test13 - - rm test_13.py - - cd .. - python3 runPytestDriver.py failWithError #The "failWithError" optional argument will cause an error exitCode if any unit tests fail. \ No newline at end of file diff --git a/ExampleFiles/__init__.py b/ExampleFiles/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/README.txt b/README.txt index f6344b0..4fec0f6 100644 --- a/README.txt +++ b/README.txt @@ -18,6 +18,10 @@ There are three ways to run unit tests: Note: For any individual test, set allowOverwrite to False when calling doTest if you want to skip UnitTesterSG from stopping to notify user when results match but result strings don't. +COMPATIBILITY WITH PYTEST AND TRAVIS CI: +Add an __init__.py file into each test directory (they can be empty) files +Then add .travis.yml to your root directory, and the script command "python3 runPytestDriver.py failWithError" within it (as in this repository). + PURPOSE OF MODULE: UnitTesterSG is a unit testing framework that is designed for nested and/or scientific/engineering data structures. It is designed primarily for testing the outputs if a single function or simulation run by storing the expected results file such that comparisons to the stored output can be made with unit tests after the function or software has been edited. However, the compare nested objects module can also be imported directly and is quite useful even outside of unit testing. diff --git a/UnitTesterSG/pytestDriver.py b/UnitTesterSG/pytestDriver.py index f689f1f..db3cf97 100644 --- a/UnitTesterSG/pytestDriver.py +++ b/UnitTesterSG/pytestDriver.py @@ -16,20 +16,27 @@ def runAllTests(failWithError=False): for directory in directoryList: print("Changing directory to "+directory) os.chdir(directory) + try: os.system("del __pycache__ /Q") #for windows os.system("rm -r __pycache__ /Q") #for linux except: pass - #Try to run the test. In the past, we we used an executable version of pytest, but now we are using "pytest.main()" so we can get the exit code, that way we can fail with error if a unit test doesn't pass. - import pytest - exitCode = pytest.main() - # os.system(sys.executable +" -m pytest") #this is like typing "python -m pytest" but uses whichever version of python should be used, important for virtual environments and different systems https://stackoverflow.com/questions/8338854/how-to-run-py-test-against-different-versions-of-python - if exitCode >= 1 and exitCode <5: - allTestsPassed = False - + + #We will check if __init__ exists, because for various situations, pytest.main( will have failures if there is no __init__. + initExists = os.path.exists('__init__.py') + if initExists: + #Try to run the test. In the past, we we used an executable version of pytest, but now we are using "pytest.main()" so we can get the exit code, that way we can fail with error if a unit test doesn't pass. + import pytest + exitCode = pytest.main() + # https://stackoverflow.com/questions/8338854/how-to-run-py-test-against-different-versions-of-python + if exitCode >= 1 and exitCode <5: + allTestsPassed = False + else: #if __init__ does not exist, we can usually still run the unit tests by running the pytest executable. + os.system(sys.executable +" -m pytest") #this is like typing "python -m pytest" but uses whichever version of python should be used, important for virtual environments and different systems os.chdir("..") - if failWithError == True: #if the failWithError flag is on due to the optional argument, we will check if all tests passed. If not, we'll raise an error. - if allTestsPassed == False: + if allTestsPassed == False: + print("At least one unit test failed.") + if failWithError == True: #if the failWithError flag is on due to the optional argument, we will check if all tests passed. If not, we'll raise an error. raise RuntimeError("At least one unit test failed.") #This is to intentionally create an error so that the Travis CI will fail. \ No newline at end of file diff --git a/setup.py b/setup.py index 696b7ef..fc171e5 100644 --- a/setup.py +++ b/setup.py @@ -20,7 +20,7 @@ EMAIL = 'AditySavara2008@u.northwestern.edu' AUTHOR = 'Aditya Savara' REQUIRES_PYTHON = '>=3.0.0' -VERSION = '6.0.0' +VERSION = '6.1.0' LICENSE = 'BSD-3-Clause' # What packages are required for this module to be executed? diff --git a/test12/__init__.py b/test12/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/test13/__init__.py b/test13/__init__.py new file mode 100644 index 0000000..e69de29