Repository: IN-CORE/pyincore (language: python)

Issue:
Add github action to run unit tests
Here is the pytest line from the old build server:

pytest --cache-clear -s pyincore/test_client.py pyincore/test_dataservice.py pyincore/test_dfr3service.py pyincore/test_spaceservice.py pyincore/test_hazardservice.py --junitxml=test-reports/results.xml

A couple of things here. 

1. We need to probably setup a conda environment because requirements.txt has a reference to ipopt
2. We need to use the test user to connect to the services to run these tests
Add github action to run unit tests
Here is the pytest line from the old build server:

pytest --cache-clear -s pyincore/test_client.py pyincore/test_dataservice.py pyincore/test_dfr3service.py pyincore/test_spaceservice.py pyincore/test_hazardservice.py --junitxml=test-reports/results.xml

A couple of things here. 

1. We need to probably setup a conda environment because requirements.txt has a reference to ipopt
2. We need to use the test user to connect to the services to run these tests
Add github action to run unit tests
Here is the pytest line from the old build server:

pytest --cache-clear -s pyincore/test_client.py pyincore/test_dataservice.py pyincore/test_dfr3service.py pyincore/test_spaceservice.py pyincore/test_hazardservice.py --junitxml=test-reports/results.xml

A couple of things here. 

1. We need to probably setup a conda environment because requirements.txt has a reference to ipopt
2. We need to use the test user to connect to the services to run these tests
Add github action to run unit tests
Here is the pytest line from the old build server:

pytest --cache-clear -s pyincore/test_client.py pyincore/test_dataservice.py pyincore/test_dfr3service.py pyincore/test_spaceservice.py pyincore/test_hazardservice.py --junitxml=test-reports/results.xml

A couple of things here. 

1. We need to probably setup a conda environment because requirements.txt has a reference to ipopt
2. We need to use the test user to connect to the services to run these tests
Add github action to run unit tests
Here is the pytest line from the old build server:

pytest --cache-clear -s pyincore/test_client.py pyincore/test_dataservice.py pyincore/test_dfr3service.py pyincore/test_spaceservice.py pyincore/test_hazardservice.py --junitxml=test-reports/results.xml

A couple of things here. 

1. We need to probably setup a conda environment because requirements.txt has a reference to ipopt
2. We need to use the test user to connect to the services to run these tests
Add github action to run unit tests
Here is the pytest line from the old build server:

pytest --cache-clear -s pyincore/test_client.py pyincore/test_dataservice.py pyincore/test_dfr3service.py pyincore/test_spaceservice.py pyincore/test_hazardservice.py --junitxml=test-reports/results.xml

A couple of things here. 

1. We need to probably setup a conda environment because requirements.txt has a reference to ipopt
2. We need to use the test user to connect to the services to run these tests


Discussion / hints:

Fix patch:
diff --git a/environment.yml b/environment.yml
new file mode 100644
index 000000000..1e69a59b7
--- /dev/null
+++ b/environment.yml
@@ -0,0 +1,27 @@
+name: base
+channels:
+  - conda-forge
+  - defaults
+dependencies:
+  - boto3
+  - deprecated
+  - fiona>=1.8.4
+  - geopandas>=0.6.1
+  - ipopt>=3.11
+  - jsonpickle>=1.1
+  - networkx>=2.2
+  - numpy>=1.16.6,<2.0a0
+  - owslib>=0.17.1
+  - pandas>=0.24.1
+  - pycodestyle>=2.6.0
+  - pyomo>=5.6
+  - pyproj>=1.9.6
+  - pytest>=3.9.0
+  - python-jose>=3.0
+  - pyyaml>=3.13
+  - rasterio>=1.0.18
+  - requests>=2.21.0
+  - rtree>=0.8.3
+  - scipy>=1.2.0
+  - shapely>=1.6.4.post1
+  - wntr>=0.1.6


Test patch:
diff --git a/.github/workflows/pytests.yml b/.github/workflows/pytests.yml
new file mode 100644
index 000000000..a1711db0d
--- /dev/null
+++ b/.github/workflows/pytests.yml
@@ -0,0 +1,48 @@
+name: pytests
+
+# Runs unit tests on:
+#  - any push to any branch
+#  - when a PR is opened/reopened - this is just for additional safety and covers the case of master -> develop PRs without new pushes
+
+# TODO: Use mamba instead of conda for installing packages. Improves on ~5mins it takes to install requirements.
+#  https://github.com/mamba-org/provision-with-micromamba
+
+on:
+  push:
+
+  pull_request:
+     types: [opened, reopened]
+
+jobs:
+  unit_test:
+    runs-on: ubuntu-latest
+    steps:
+      - name: Checkout source code
+        uses: actions/checkout@v2
+
+      - name: Cache conda
+        uses: actions/cache@v2
+        env:
+          # Increase this value to reset cache if environment.yml has not changed
+          CACHE_NUMBER: 0
+        with:
+          path: ~/conda_pkgs_dir
+          key:
+            ${{ runner.os }}-conda-${{ env.CACHE_NUMBER }}-${{
+            hashFiles('environment.yml') }}
+
+      - name: Install miniconda
+        uses: conda-incubator/setup-miniconda@v2
+        with:
+          miniconda-version: "latest"
+          mamba-version: "*"
+          use-mamba: true
+          python-version: 3.8
+          activate-environment: base
+          environment-file: environment.yml
+          use-only-tar-bz2: true
+
+      - name: Run tests with pytest
+        run: |
+          echo "${{secrets.PYTEST_USER_TOKEN}}" > tests/pyincore/.incorepw
+          $CONDA/bin/python -m pytest --ignore=tests/test_format.py --ignore=tests/pyincore/analyses