Skip to content

Commit

Permalink
revise test runner conf
Browse files Browse the repository at this point in the history
  • Loading branch information
jokester committed Jun 9, 2024
1 parent 1d46648 commit a54baeb
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 38 deletions.
1 change: 1 addition & 0 deletions .env.test
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Env variables for tests
TESTING=YES
LOG_LEVEL=DEBUG
SITE_NAME=萌翻TEST
SECRET_KEY=SECRET
Expand Down
36 changes: 28 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,21 +1,41 @@
venv:
python3 -mvenv venv
PYTEST_COV_ARGS = --cov=app --cov-report=term --cov-report=xml:cov.xml

FORCE: ;

create-venv:
python3.10 -mvenv venv

deps:
venv/bin/pip install -r requirements.txt

remove-venv: FORCE
rm -rf venv

recreate-venv: remove-venv create-venv

format:
venv/bin/ruff format

test:
@./pytest --html=report.html --self-contained-html
requirements.txt: deps-top.txt recreate-venv
venv/bin/pip install -r deps-top.txt
echo '# GENERATED: run make requirements.txt to recreate lock file' > requirements.txt
venv/bin/pipdeptree --freeze >> requirements.txt

test: test_all

test_all_cov:
venv/bin/pytest --html=report.html --self-contained-html ${PYTEST_COV_ARGS[@]}

test_all:
venv/bin/pytest --html=report.html --self-contained-html

test_p:
@./pytest -n 8
test_all_parallel:
venv/bin/pytest -n 8

test_single:
@bash -c "set -uexo allexport && source .env.test && exec venv/bin/pytest --capture=sys --log-cli-level=DEBUG tests/base/test_not_exist_error.py"
venv/bin/pytest tests/base/test_not_exist_error.py

test_logging:
#--capture=no
# WTF: setting level to above WARNING not working?
@bash -c "set -uexo allexport && source .env.test && exec venv/bin/pytest --capture=sys --log-cli-level=DEBUG tests/base/test_it_runs.py"
# @bash -c "set -uexo allexport && source .env.test && exec venv/bin/pytest --capture=sys --log-cli-level=DEBUG tests/base/test_it_runs.py"
2 changes: 2 additions & 0 deletions app/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
LOG_PATH = env.get("LOG_PATH")
MAX_CONTENT_LENGTH = int(env.get("MAX_CONTENT_LENGTH_MB", 1024)) * 1024 * 1024
ADMIN_EMAIL = env["ADMIN_EMAIL"]
# TODO remove code relying on this
TESTING = env.get('TESTING') == 'YES'
# -----------
# Mongo 数据库
# -----------
Expand Down
3 changes: 3 additions & 0 deletions deps-top.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ gunicorn==20.0.4 # 生产环境服务器
pytest==8.2.1 # 测试框架
pytest-cov==5.0.0 # 测试覆盖率
pytest-xdist==3.6.1 # 并发测试支持
pytest-dotenv==0.5.2
pytest-html==4.1.1

flask-babel==1.0.0 # i18n
mongoengine==0.20.0 # Mongo数据库
mongomock==4.1.2
Expand Down
6 changes: 0 additions & 6 deletions pytest

This file was deleted.

4 changes: 2 additions & 2 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
[pytest]
generate_report_on_test = True
; 覆盖率配置,需要时开启(可配合VSCode的Coverage Gutters使用)
addopts = -s
; addopts = -s --cov=app --cov-report=term --cov-report=xml:cov.xml
addopts = --log-level=INFO
; 忽略第三方库Warining
filterwarnings =
ignore:count is deprecated. Use Collection.count_documents instead.:DeprecationWarning
ignore:Using or importing the ABCs .* is deprecated.*:DeprecationWarning
env_files = .env.test
58 changes: 36 additions & 22 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,26 +1,25 @@
# GENERATED: run make requirements.txt to recreate lock file
asgiref==3.7.2
typing_extensions==4.11.0
attrs==23.2.0
blinker==1.7.0
typing_extensions==4.12.2
Flask-APIKit==0.0.7
Flask==2.2.5
click==8.1.3
itsdangerous==2.0.1
Jinja2==3.1.3
Jinja2==3.1.4
MarkupSafe==2.1.5
Werkzeug==3.0.2
Werkzeug==3.0.3
MarkupSafe==2.1.5
marshmallow==3.0.0b20
Flask-Babel==1.0.0
Babel==2.14.0
Babel==2.15.0
Flask==2.2.5
click==8.1.3
itsdangerous==2.0.1
Jinja2==3.1.3
Jinja2==3.1.4
MarkupSafe==2.1.5
Werkzeug==3.0.2
Werkzeug==3.0.3
MarkupSafe==2.1.5
Jinja2==3.1.3
Jinja2==3.1.4
MarkupSafe==2.1.5
pytz==2024.1
flower==0.9.5
Expand All @@ -33,7 +32,7 @@ flower==0.9.5
click==8.1.3
click-repl==0.3.0
click==8.1.3
prompt-toolkit==3.0.43
prompt_toolkit==3.0.46
wcwidth==0.2.13
kombu==5.3.7
amqp==5.2.0
Expand All @@ -46,7 +45,7 @@ flower==0.9.5
humanize==4.9.0
prometheus-client==0.8.0
pytz==2024.1
tornado==6.4
tornado==6.4.1
google-cloud-storage==1.33.0
google-auth==1.35.0
cachetools==4.2.4
Expand All @@ -66,11 +65,11 @@ google-cloud-storage==1.33.0
pyasn1==0.6.0
setuptools==65.5.0
six==1.16.0
googleapis-common-protos==1.63.0
googleapis-common-protos==1.63.1
protobuf==4.25.3
protobuf==4.25.3
requests==2.22.0
certifi==2024.2.2
certifi==2024.6.2
chardet==3.0.4
idna==2.8
urllib3==1.25.11
Expand All @@ -87,7 +86,7 @@ google-cloud-storage==1.33.0
google-crc32c==1.5.0
six==1.16.0
requests==2.22.0
certifi==2024.2.2
certifi==2024.6.2
chardet==3.0.4
idna==2.8
urllib3==1.25.11
Expand All @@ -102,38 +101,54 @@ oss2==2.7.0
aliyun-python-sdk-core-v3==2.13.3
jmespath==0.10.0
pycryptodome==3.20.0
aliyun-python-sdk-kms==2.16.2
aliyun-python-sdk-kms==2.16.3
aliyun-python-sdk-core==2.15.1
cryptography==42.0.5
cryptography==42.0.8
cffi==1.16.0
pycparser==2.22
jmespath==0.10.0
crcmod==1.7
pycryptodome==3.20.0
requests==2.22.0
certifi==2024.2.2
certifi==2024.6.2
chardet==3.0.4
idna==2.8
urllib3==1.25.11
Pillow==8.0.1
pip==23.0.1
pipdeptree==2.13.2
pytest-cov==5.0.0
coverage==7.4.4
coverage==7.5.3
pytest==8.2.1
exceptiongroup==1.2.1
iniconfig==2.0.0
packaging==24.0
pluggy==1.5.0
tomli==2.0.1
pytest-forked==1.6.0
py==1.11.0
pytest-dotenv==0.5.2
pytest==8.2.1
exceptiongroup==1.2.1
iniconfig==2.0.0
packaging==24.0
pluggy==1.5.0
tomli==2.0.1
python-dotenv==1.0.1
pytest-html==4.1.1
Jinja2==3.1.4
MarkupSafe==2.1.5
pytest==8.2.1
exceptiongroup==1.2.1
iniconfig==2.0.0
packaging==24.0
pluggy==1.5.0
tomli==2.0.1
pytest-metadata==3.1.1
pytest==8.2.1
exceptiongroup==1.2.1
iniconfig==2.0.0
packaging==24.0
pluggy==1.5.0
tomli==2.0.1
pytest-xdist==3.6.1
execnet==2.1.1
pytest==8.2.1
Expand All @@ -144,5 +159,4 @@ pytest-xdist==3.6.1
tomli==2.0.1
redis==5.0.3
async-timeout==4.0.3
ruff==0.4.1
toml==0.10.2
ruff==0.4.8

0 comments on commit a54baeb

Please sign in to comment.