From 8c5ee627fad30e33a90bdbcd25c787186d4b763a Mon Sep 17 00:00:00 2001 From: Dominik Neise Date: Wed, 26 Jun 2019 17:01:13 +0200 Subject: [PATCH 1/6] just use pytest --- .circleci/config.yml | 4 +--- test_replays/{test_all.py => test_replays.py} | 0 2 files changed, 1 insertion(+), 3 deletions(-) rename test_replays/{test_all.py => test_replays.py} (100%) diff --git a/.circleci/config.yml b/.circleci/config.yml index 1370bc61..c654bffd 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -9,9 +9,7 @@ my-steps: &steps - run: flake8 . --count --select=E901,E999,F821,F822,F823 --show-source --statistics # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide - run: flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics - #- run: pytest # test_s2gs test_replays - - run: python -m unittest discover test_s2gs - - run: python -m unittest discover test_replays + - run: pytest jobs: Python2: diff --git a/test_replays/test_all.py b/test_replays/test_replays.py similarity index 100% rename from test_replays/test_all.py rename to test_replays/test_replays.py From 4b899d35c59e9eb6e040c54b8c6ddf89b7176e62 Mon Sep 17 00:00:00 2001 From: Dominik Neise Date: Wed, 26 Jun 2019 17:05:51 +0200 Subject: [PATCH 2/6] pytest needs the package under test to be installed --- .circleci/config.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.circleci/config.yml b/.circleci/config.yml index c654bffd..8f34650f 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -5,6 +5,7 @@ my-steps: &steps - run: sudo pip install -r requirements.txt - run: sudo pip install flake8 pytest - run: python --version ; pip --version ; pwd ; ls -l + - run: pip install --user . # stop the build if there are Python syntax errors or undefined names - run: flake8 . --count --select=E901,E999,F821,F822,F823 --show-source --statistics # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide From eb1ba54a765dd969cdacb59e18c2c2ff72baec8a Mon Sep 17 00:00:00 2001 From: Dominik Neise Date: Wed, 26 Jun 2019 17:01:13 +0200 Subject: [PATCH 3/6] just use pytest --- .circleci/config.yml | 4 +--- test_replays/{test_all.py => test_replays.py} | 0 2 files changed, 1 insertion(+), 3 deletions(-) rename test_replays/{test_all.py => test_replays.py} (100%) diff --git a/.circleci/config.yml b/.circleci/config.yml index 1370bc61..c654bffd 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -9,9 +9,7 @@ my-steps: &steps - run: flake8 . --count --select=E901,E999,F821,F822,F823 --show-source --statistics # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide - run: flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics - #- run: pytest # test_s2gs test_replays - - run: python -m unittest discover test_s2gs - - run: python -m unittest discover test_replays + - run: pytest jobs: Python2: diff --git a/test_replays/test_all.py b/test_replays/test_replays.py similarity index 100% rename from test_replays/test_all.py rename to test_replays/test_replays.py From 74905d89352826837fe95ad100a305c57c6a2365 Mon Sep 17 00:00:00 2001 From: Dominik Neise Date: Wed, 26 Jun 2019 17:05:51 +0200 Subject: [PATCH 4/6] pytest needs the package under test to be installed --- .circleci/config.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.circleci/config.yml b/.circleci/config.yml index c654bffd..8f34650f 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -5,6 +5,7 @@ my-steps: &steps - run: sudo pip install -r requirements.txt - run: sudo pip install flake8 pytest - run: python --version ; pip --version ; pwd ; ls -l + - run: pip install --user . # stop the build if there are Python syntax errors or undefined names - run: flake8 . --count --select=E901,E999,F821,F822,F823 --show-source --statistics # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide From 17530b113fa95556d1afd41ce705c32b53fc9cb3 Mon Sep 17 00:00:00 2001 From: Dominik Neise Date: Wed, 26 Jun 2019 20:24:45 +0200 Subject: [PATCH 5/6] add docs for testing --- README.rst | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/README.rst b/README.rst index ca2dfb3e..fa78c025 100644 --- a/README.rst +++ b/README.rst @@ -259,21 +259,36 @@ Please review the `CONTRIBUTING.md`_ file and get in touch with us before doing Testing ------------------- -We use the built in ``unittest`` module for testing. If you are still on Python 2.6 you will need to install ``unittest2`` because our test suite requires newer features than are included in the main distribution. +We use ``pytest`` for testing. If you don't have it just ``pip install pytest``. -To run the tests just use:: +To run the tests, just do:: - python test_replays/test_all.py - python test_s2gs/test_all.py + pytest -When repeatedly running tests it can be very helpful to make sure you've set a local cache directory to prevent long fetch times from battle.net:: - SC2READER_CACHE_DIR=local_cache PYTHONPATH=. python -m unittest test_replays.test_all +When repeatedly running tests it can be very helpful to make sure you've set a local cache directory to prevent long fetch times from battle.net. +So make some local cache folder:: + + mkdir cache + +And then run the tests like this:: + + SC2READER_CACHE_DIR=./cache pytest To run just one test: - SC2READER_CACHE_DIR=local_cache PYTHONPATH=. python -m unittest test_replays.test_all.TestReplays.test_38749 + SC2READER_CACHE_DIR=./cache pytest test_replays/test_replays.py::TestReplays::test_38749 + +If you'd like to see which are the 10 slowest tests (to find performance issues maybe):: + + pytest --durations=10 + +If you want ``pytest`` to stop after the first failing test:: + + pytest -x + +Have a look at the very fine ``pytest`` docs for more information. Good luck, have fun! From 5cd2b8472212e9a6640f2b2d45301fcbb7197bf5 Mon Sep 17 00:00:00 2001 From: Dominik Neise Date: Wed, 26 Jun 2019 20:44:15 +0200 Subject: [PATCH 6/6] add pytest as test requirement to setup.py --- setup.py | 1 + 1 file changed, 1 insertion(+) diff --git a/setup.py b/setup.py index c5d1d694..d067af22 100644 --- a/setup.py +++ b/setup.py @@ -48,6 +48,7 @@ }, install_requires=['mpyq>=0.2.3', 'argparse', 'ordereddict', 'unittest2', 'pil'] if float(sys.version[:3]) < 2.7 else ['mpyq>=0.2.4'], + tests_require=["pytest"], packages=setuptools.find_packages(), include_package_data=True, zip_safe=True