diff --git a/.github/workflows/pytest.yaml b/.github/workflows/pytest.yaml new file mode 100644 index 0000000..b896426 --- /dev/null +++ b/.github/workflows/pytest.yaml @@ -0,0 +1,34 @@ +name: Pytest + +on: + push: + pull_request: + branches: + - main +jobs: + test: + runs-on: ubuntu-latest + strategy: + matrix: + python-version: ['3.10'] + max-parallel: 1 + env: # Or as an environment variable + PROJECT: ${{ secrets.PROJECT }} + SOURCE_TABLE: ${{ secrets.SOURCE_TABLE }} + DESTINATION_TABLE: ${{ secrets.DESTINATION_TABLE }} + DATASET: ${{ secrets.DATASET }} + SA_JSON: ${{ secrets.SA_JSON }} + steps: + - uses: actions/checkout@v3 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v3 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: | + python -m pip install --upgrade pip + if [ -f requirements.txt ]; then pip install -r requirements.txt; fi + python -m pip install pytest==7.4.3 + - name: Test with pytest + run: | + python -m pytest -vv diff --git a/tests/__init__.py b/tests/__init__.py index f93b7e1..86bc523 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -20,7 +20,15 @@ def env_var_loader(file_name, file_path=None): if os.path.isfile(env_path): load_dotenv(dotenv_path=env_path) - +# load env vars env_var_loader("tests/.env") +# load path to get python files sys.path.append(os.path.join(os.getcwd(), 'cloud_function')) + +# load sa if applicable +if os.environ.get('SA_JSON'): + file_name = 'sa.json' + with open(file_name, 'r') as f: + f.write(os.environ['SA_JSON']) + os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = file_name