-
Notifications
You must be signed in to change notification settings - Fork 0
test: get pytest working with basic DB tests #45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
f4cd0f3
b1dfcec
7206696
439643a
14dd024
d99c64c
e020dc9
459af20
f7794c2
9cbcbb8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,124 @@ | ||
| name: backend | ||
|
|
||
| on: | ||
| pull_request: | ||
|
|
||
| permissions: | ||
| contents: read | ||
| issues: write | ||
|
|
||
| jobs: | ||
| tests: | ||
| name: pytest | ||
| runs-on: ubuntu-latest | ||
|
|
||
| defaults: | ||
| run: | ||
| working-directory: ./backend | ||
|
|
||
| services: | ||
| postgres: | ||
| image: postgres:16 | ||
| env: | ||
| POSTGRES_DB: postgres | ||
| POSTGRES_USER: admin | ||
| POSTGRES_PASSWORD: password | ||
| ports: | ||
| - 5432:5432 | ||
| options: >- | ||
| --health-cmd "pg_isready -U admin -d postgres" | ||
| --health-interval 10s | ||
| --health-timeout 5s | ||
| --health-retries 10 | ||
|
|
||
| env: | ||
| POSTGRES_MODE: local | ||
| POSTGRES_HOST: 127.0.0.1 | ||
| POSTGRES_PORT: 5432 | ||
| POSTGRES_DATABASE: postgres | ||
| POSTGRES_USER: admin | ||
| POSTGRES_PASSWORD: password | ||
| POSTGRES_CONNECT_TIMEOUT: 10 | ||
| STORAGE_MODE: local | ||
| LOCAL_STORAGE_BASE_PATH: /tmp/can-sr-uploads | ||
| AZURE_OPENAI_MODE: key | ||
| AZURE_DOC_INT_MODE: key | ||
| PYTHONUNBUFFERED: 1 | ||
| AZURE_DOC_INT_ENDPOINT: fake | ||
| ENTREZ_EMAIL: fake | ||
| ENTREZ_API_KEY: fake | ||
| AZURE_STORAGE_CONNECTION_STRING: fake | ||
| SCOPUS_API_URL: fake | ||
|
|
||
|
|
||
| steps: | ||
| - name: Check out repository | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| fetch-depth: 0 | ||
|
|
||
| - name: Set up Python | ||
| uses: actions/setup-python@v5 | ||
| with: | ||
| python-version: "3.11" | ||
| cache: pip | ||
| cache-dependency-path: | | ||
| backend/requirements.txt | ||
| backend/requirements_dev.txt | ||
|
|
||
| - name: Install dependencies | ||
| run: | | ||
| python -m pip install --upgrade pip | ||
| pip install -r requirements.txt -r requirements_dev.txt | ||
|
|
||
| - name: Run pytest with coverage | ||
| run: | | ||
| mkdir -p /tmp/can-sr-uploads | ||
| python -m coverage run -m pytest tests/ | ||
| python -m coverage xml -o coverage.xml | ||
| python -m coverage report | ||
|
|
||
| - name: Generate diff coverage | ||
| if: github.event.pull_request.base.sha != '' | ||
| continue-on-error: true | ||
| run: | | ||
| diff-cover coverage.xml \ | ||
| --compare-branch=${{ github.event.pull_request.base.sha }} \ | ||
| --markdown-report diff-cover.md \ | ||
| --html-report diff-cover.html | ||
|
|
||
| - name: Build diff coverage comment body | ||
| if: github.event.pull_request.base.sha != '' | ||
| run: | | ||
| { | ||
| echo "<!-- can-sr-diff-coverage -->" | ||
| echo "## Diff coverage" | ||
| if [ -f diff-cover.md ]; then | ||
| cat diff-cover.md | ||
| else | ||
| echo "_Diff coverage report could not be generated for this run._" | ||
| fi | ||
| echo | ||
| echo "Coverage XML and HTML reports are attached to this workflow run as artifacts." | ||
| } > diff-coverage-comment.md | ||
|
|
||
| - name: Publish diff coverage comment | ||
| if: github.event.pull_request.base.sha != '' | ||
| continue-on-error: true | ||
| uses: edumserrano/find-create-or-update-comment@v2 | ||
| with: | ||
| issue-number: ${{ github.event.pull_request.number }} | ||
| body-includes: '<!-- can-sr-diff-coverage -->' | ||
| comment-author: 'github-actions[bot]' | ||
| body-path: backend/diff-coverage-comment.md | ||
| edit-mode: replace | ||
|
|
||
| - name: Upload coverage artifacts | ||
| if: always() | ||
| uses: actions/upload-artifact@v4 | ||
| with: | ||
| name: coverage-reports | ||
| if-no-files-found: ignore | ||
| path: | | ||
| backend/coverage.xml | ||
| backend/diff-cover.html | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -519,3 +519,16 @@ The importer currently supports these common include names: | |
|
|
||
| If you put **rispy keys directly** in `include:` (e.g. `doi`, `authors`), the | ||
| importer will also attempt to copy them through as-is. | ||
|
|
||
|
|
||
|
|
||
| ## Running tests | ||
|
|
||
| From the backend/ directory, | ||
| 1. `pip install -r requirements_dev.txt` | ||
| 2. `pytest` | ||
|
|
||
| To calculate coverage, | ||
| 1. `coverage run -m pytest` | ||
| 2. `coverage html` | ||
| 3. Open `./htmlcov/index.html` in a browser to view the report and browse around line by line | ||
|
Comment on lines
+525
to
+534
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note testing instructions |
||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm surprised we've gotten this far without |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| [tool.pytest.ini_options] | ||
| asyncio_mode = "auto" | ||
|
|
||
| [tool.coverage.run] | ||
| source = ["."] | ||
| omit = [ | ||
| "tests/*", | ||
| "venv/", | ||
| ] | ||
| [tool.coverage.report] | ||
| show_missing = true | ||
| skip_covered = true |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| pytest==9.0.2 | ||
| pytest-asyncio==1.3.0 | ||
| coverage==7.6.12 | ||
| diff-cover==9.1.1 | ||
| ipython==9 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| import asyncio | ||
|
|
||
|
|
||
| def test_smoke(): | ||
| assert True | ||
|
|
||
|
|
||
|
|
||
| async def test_my_async_code(): | ||
| result = await asyncio.sleep(0.01, result="success") | ||
| assert result == "success" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally, this action would add a comment on each PR listing the coverage of its diff. Unfortunately I can't easily get this working, running into permission issues I don't have time to debug.
It does hoever successfully upload an artifact you can download, but that's not much faster than checking coverage yourself locally