Skip to content

Commit

Permalink
use pytest inplace of unittest
Browse files Browse the repository at this point in the history
  • Loading branch information
cedric05 authored Aug 27, 2024
1 parent 5544f10 commit fdd19ed
Show file tree
Hide file tree
Showing 7 changed files with 146 additions and 29 deletions.
2 changes: 1 addition & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
// "forwardPorts": [],

// Use 'postCreateCommand' to run commands after the container is created.
"postCreateCommand": "pip3 install --user -r all_requirements.txt",
"postCreateCommand": "pip install poetry && poetry install ",

// Comment out to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
"remoteUser": "vscode",
Expand Down
10 changes: 8 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,14 @@ jobs:
poetry install --all-extras --no-root
- name: Run tests
run: |
docker run -d -p 8000:80 kennethreitz/httpbin
python -m unittest
# current dothttp prints to terminal, which is not good for pytest.
# although, for test cases, we should ask those who prints to return
pytest -s --html=report.html --self-contained-html
- name: Upload test report
uses: actions/upload-artifact@v2
with:
name: test-report
path: report.html
# benchmark is not working for long time.
# TODO
# - name: Run benchmark
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/python-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ jobs:
# unit tests need python-magic
# package in pypi woudn't need python-magic
# for integration tests
docker run -d -p 8000:80 kennethreitz/httpbin
python -m unittest
pytest -s
- name: Build Distribution
run: |
# install prerequisites
Expand Down
Empty file removed __init__.py
Empty file.
138 changes: 115 additions & 23 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ parsys-requests-unixsocket = "0.3.2"
requests-aws4auth = "1.3.1"
requests-ntlm = "1.3.0"
restrictedpython = "7.2"
faker = "27.4.0"
faker = "28.0.0"
requests-hawk = "1.2.1"
msal = "1.30.0"
pyyaml = "6.0.2"
Expand All @@ -44,6 +44,7 @@ flask = "3.0.2"
python-magic = "^0.4.27"
js2py = "0.74"
flask-cors = "^4.0.1"
pytest = "^8.3.2"

[tool.poetry.extras]
js = ["js2py"]
Expand Down
19 changes: 19 additions & 0 deletions test/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import pytest
import subprocess
import time

@pytest.fixture(scope='session', autouse=True)
def start_httpbin_container():
# Setup: Start the Docker container
container_id = subprocess.check_output(
["docker", "run", "-d", "-p", "8000:80", "kennethreitz/httpbin"]
).decode().strip()

# Wait for the container to be ready
time.sleep(5) # Adjust the sleep time as needed

yield

# Teardown: Stop and remove the Docker container
subprocess.run(["docker", "stop", container_id])
subprocess.run(["docker", "rm", container_id])

0 comments on commit fdd19ed

Please sign in to comment.