Skip to content

Commit c7b5f96

Browse files
authored
Re-activate pytests (#208)
1 parent 3330134 commit c7b5f96

File tree

136 files changed

+2393
-90560
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

136 files changed

+2393
-90560
lines changed

Diff for: .azdo/azure-pipeline.yaml

+4-3
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,12 @@ extends:
3030
jobs:
3131
- job: CG_Prep
3232
steps:
33-
# Component Governance does not support pyproject.toml yet.
34-
# for this reason, use toml-to-requirements to export dependencies into a requirements.txt file.
33+
# Component Governance (CG) does not support pyproject.toml yet.
34+
# For this reason, use toml-to-requirements to export dependencies into a requirements.txt file.
35+
# CG will auto-detect the requirements.txt file and use it to scan for dependencies.
3536
- script: |
3637
pip install toml-to-requirements
37-
toml-to-req --toml-file pyproject.toml --poetry --optional-lists dev,test,backend,frontend
38+
toml-to-req --toml-file backend/pyproject.toml --poetry --optional-lists dev,test,backend,frontend
3839
# toml-to-req is not perfect. It will leave wildcard characters in the requirements.txt file which we remove
3940
sed -i 's/\*//g' requirements.txt
4041
displayName: 'Export python dependencies to requirements.txt for CG'

Diff for: .devcontainer/Dockerfile

+11-13
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
FROM python:3.10
1+
# For more information about the base image visit:
2+
# https://mcr.microsoft.com/en-us/artifact/mar/devcontainers/python/about
3+
FROM mcr.microsoft.com/devcontainers/python:3.10-bookworm
24

3-
# avoid common warnings
5+
# disable common warning messages
46
ENV DEBIAN_FRONTEND=noninteractive
57
ENV PIP_ROOT_USER_ACTION=ignore
68
ENV PIP_DISABLE_PIP_VERSION_CHECK=1
79

810
# configure environment
911
ARG ENVNAME="GraphRAG"
1012
ARG USERNAME=vscode
11-
ARG USER_UID=1001
12-
ARG USER_GID=$USER_UID
1313
ARG WORKDIR=/${ENVNAME}
1414

1515
# install python, pip, git, and other required tools
@@ -53,13 +53,11 @@ RUN rm -rf /var/lib/apt/lists/* \
5353
# set the location for the virtual environments to be outside the project directory
5454
ENV POETRY_VIRTUALENVS_IN_PROJECT=true
5555

56-
# set up non-root user
57-
RUN useradd -ms /bin/bash -u ${USER_GID} ${USERNAME} \
58-
&& echo "${USERNAME}:${USERNAME}" | chpasswd \
59-
# add user to sudo group and docker group
56+
# a non-root user (vscode) already exist in the base image. Add it to sudo group and docker group
57+
RUN echo "${USERNAME}:${USERNAME}" | chpasswd \
6058
&& adduser ${USERNAME} sudo \
61-
&& echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers \
62-
&& usermod -aG docker ${USERNAME}
59+
&& adduser ${USERNAME} docker \
60+
&& echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers
6361

6462
# switch to non-root user
6563
USER ${USERNAME}
@@ -73,13 +71,13 @@ ENV PATH="/home/${USERNAME}/.local/bin:${PATH}"
7371
ENV PATH=/graphrag-accelerator/.venv/bin:$PATH
7472

7573
# copy the project files into the container and set ownership
76-
COPY --chown=${USERNAME}:${USER_GID} . ${WORKDIR}
74+
COPY --chown=${USERNAME}:${USERNAME} . ${WORKDIR}
7775

7876
COPY entrypoint.sh /usr/local/bin/entrypoint.sh
7977

8078
# Create directories for vscode server and extensions
81-
RUN mkdir -p /home/$USERNAME/.vscode-server/extensions \
82-
&& chown -R $USER_UID:$USER_GID /home/$USERNAME/.vscode-server
79+
RUN mkdir -p ~/.vscode-server/extensions \
80+
&& chown -R $USERNAME:$USERNAME ~/.vscode-server
8381

8482
ENTRYPOINT [ "/usr/local/bin/entrypoint.sh" ]
8583
CMD ["bash"]

Diff for: .github/workflows/tests.yaml

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
name: Testing
2+
on:
3+
workflow_dispatch: # triggered manually via the GitHub UI
4+
pull_request: # triggered when a PR is created or updated
5+
types:
6+
- opened
7+
- reopened
8+
- synchronize
9+
- ready_for_review
10+
paths: # only trigger on changes in specific directories
11+
- '.github/**/*.yaml'
12+
- 'backend/**'
13+
- 'docker/**'
14+
- 'backend/poetry.lock'
15+
- 'backend/pyproject.toml'
16+
17+
env:
18+
PYTHON_VERSION: '3.10'
19+
20+
jobs:
21+
tests:
22+
runs-on: windows-latest
23+
steps:
24+
- name: Checkout repository
25+
uses: actions/checkout@v4
26+
27+
- name: Install python
28+
uses: actions/setup-python@v5
29+
with:
30+
python-version: '3.10'
31+
32+
- name: Install Azurite
33+
shell: bash
34+
run: |
35+
npm install -g azurite
36+
azurite --silent &
37+
38+
# For more information on installation/setup of Azure Cosmos DB Emulator
39+
# https://learn.microsoft.com/en-us/azure/cosmos-db/how-to-develop-emulator?tabs=docker-linux%2Cpython&pivots=api-nosql
40+
# Note: the emulator is only available on Windows runners. It can take longer than the default to initially startup so we increase the default timeout.
41+
# If a job fails due to timeout, restarting the cicd job usually resolves the problem.
42+
- name: Install Azure Cosmos DB emulator
43+
run: |
44+
Write-Host "Launching Cosmos DB Emulator"
45+
Import-Module "$env:ProgramFiles\Azure Cosmos DB Emulator\PSModules\Microsoft.Azure.CosmosDB.Emulator"
46+
Start-CosmosDbEmulator -Timeout 500
47+
48+
- name: Install dependencies
49+
working-directory: ${{ github.workspace }}/backend
50+
run: |
51+
pip install poetry
52+
poetry config virtualenvs.create false
53+
poetry install --with test
54+
55+
- name: Run pytests
56+
working-directory: ${{ github.workspace }}/backend
57+
run: |
58+
pytest --cov=src --junitxml=test-results.xml tests/
59+
60+
- name: Upload test results
61+
uses: actions/upload-artifact@v4
62+
with:
63+
name: pytest-results
64+
path: ${{ github.workspace }}/backend/test-results.xml
65+
# Use always() to always run this step to publish test results when there are test failures
66+
if: ${{ always() }}

0 commit comments

Comments
 (0)