Skip to content

Commit 793a491

Browse files
committed
Overhaul tests to use py.test
1 parent d41a31a commit 793a491

17 files changed

+307
-326
lines changed

.github/workflows/run_tests.yaml

+42-7
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,53 @@ jobs:
1818
cache-dependency-path: |
1919
**/requirements*txt
2020
launch.py
21-
- name: Run tests
22-
run: python launch.py --tests test --no-half --disable-opt-split-attention --use-cpu all --skip-torch-cuda-test
21+
- name: Install test dependencies
22+
run: pip install wait-for-it -r requirements-test.txt
23+
env:
24+
PIP_DISABLE_PIP_VERSION_CHECK: "1"
25+
PIP_PROGRESS_BAR: "off"
26+
- name: Setup environment
27+
run: python launch.py --skip-torch-cuda-test --exit
2328
env:
2429
PIP_DISABLE_PIP_VERSION_CHECK: "1"
2530
PIP_PROGRESS_BAR: "off"
2631
TORCH_INDEX_URL: https://download.pytorch.org/whl/cpu
2732
WEBUI_LAUNCH_LIVE_OUTPUT: "1"
28-
- name: Upload main app stdout-stderr
33+
PYTHONUNBUFFERED: "1"
34+
- name: Start test server
35+
run: >
36+
python -m coverage run
37+
--data-file=.coverage.server
38+
launch.py
39+
--skip-prepare-environment
40+
--skip-torch-cuda-test
41+
--test-server
42+
--no-half
43+
--disable-opt-split-attention
44+
--use-cpu all
45+
--add-stop-route
46+
2>&1 | tee output.txt &
47+
- name: Run tests
48+
run: |
49+
wait-for-it --service 127.0.0.1:7860 -t 600
50+
python -m pytest -vv --junitxml=test/results.xml --cov . --cov-report=xml --verify-base-url test
51+
- name: Kill test server
52+
if: always()
53+
run: curl -vv -XPOST http://127.0.0.1:7860/_stop && sleep 10
54+
- name: Show coverage
55+
run: |
56+
python -m coverage combine .coverage*
57+
python -m coverage report -i
58+
python -m coverage html -i
59+
- name: Upload main app output
60+
uses: actions/upload-artifact@v3
61+
if: always()
62+
with:
63+
name: output
64+
path: output.txt
65+
- name: Upload coverage HTML
2966
uses: actions/upload-artifact@v3
3067
if: always()
3168
with:
32-
name: stdout-stderr
33-
path: |
34-
test/stdout.txt
35-
test/stderr.txt
69+
name: htmlcov
70+
path: htmlcov

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,5 @@ notification.mp3
3535
/cache.json*
3636
/config_states/
3737
/node_modules
38-
/package-lock.json
38+
/package-lock.json
39+
/.coverage*

launch.py

+12-20
Original file line numberDiff line numberDiff line change
@@ -310,12 +310,8 @@ def prepare_environment():
310310
print("Exiting because of --exit argument")
311311
exit(0)
312312

313-
if args.tests and not args.no_tests:
314-
exitcode = tests(args.tests)
315-
exit(exitcode)
316313

317-
318-
def tests(test_dir):
314+
def configure_for_tests():
319315
if "--api" not in sys.argv:
320316
sys.argv.append("--api")
321317
if "--ckpt" not in sys.argv:
@@ -325,21 +321,8 @@ def tests(test_dir):
325321
sys.argv.append("--skip-torch-cuda-test")
326322
if "--disable-nan-check" not in sys.argv:
327323
sys.argv.append("--disable-nan-check")
328-
if "--no-tests" not in sys.argv:
329-
sys.argv.append("--no-tests")
330-
331-
print(f"Launching Web UI in another process for testing with arguments: {' '.join(sys.argv[1:])}")
332324

333325
os.environ['COMMANDLINE_ARGS'] = ""
334-
with open(os.path.join(script_path, 'test/stdout.txt'), "w", encoding="utf8") as stdout, open(os.path.join(script_path, 'test/stderr.txt'), "w", encoding="utf8") as stderr:
335-
proc = subprocess.Popen([sys.executable, *sys.argv], stdout=stdout, stderr=stderr)
336-
337-
import test.server_poll
338-
exitcode = test.server_poll.run_tests(proc, test_dir)
339-
340-
print(f"Stopping Web UI process with id {proc.pid}")
341-
proc.kill()
342-
return exitcode
343326

344327

345328
def start():
@@ -351,6 +334,15 @@ def start():
351334
webui.webui()
352335

353336

354-
if __name__ == "__main__":
355-
prepare_environment()
337+
def main():
338+
if not args.skip_prepare_environment:
339+
prepare_environment()
340+
341+
if args.test_server:
342+
configure_for_tests()
343+
356344
start()
345+
346+
347+
if __name__ == "__main__":
348+
main()

modules/cmd_args.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
parser.add_argument("--reinstall-xformers", action='store_true', help="launch.py argument: install the appropriate version of xformers even if you have some version already installed")
1313
parser.add_argument("--reinstall-torch", action='store_true', help="launch.py argument: install the appropriate version of torch even if you have some version already installed")
1414
parser.add_argument("--update-check", action='store_true', help="launch.py argument: chck for updates at startup")
15-
parser.add_argument("--tests", type=str, default=None, help="launch.py argument: run tests in the specified directory")
16-
parser.add_argument("--no-tests", action='store_true', help="launch.py argument: do not run tests even if --tests option is specified")
15+
parser.add_argument("--test-server", action='store_true', help="launch.py argument: configure server for testing")
16+
parser.add_argument("--skip-prepare-environment", action='store_true', help="launch.py argument: skip all environment preparation")
1717
parser.add_argument("--skip-install", action='store_true', help="launch.py argument: skip installation of packages")
1818
parser.add_argument("--data-dir", type=str, default=os.path.dirname(os.path.dirname(os.path.realpath(__file__))), help="base path where all user data is stored")
1919
parser.add_argument("--config", type=str, default=sd_default_config, help="path to config which constructs model",)

pyproject.toml

+3
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,6 @@ ignore = [
3030
[tool.ruff.flake8-bugbear]
3131
# Allow default arguments like, e.g., `data: List[str] = fastapi.Query(None)`.
3232
extend-immutable-calls = ["fastapi.Depends", "fastapi.security.HTTPBasic"]
33+
34+
[tool.pytest.ini_options]
35+
base_url = "http://127.0.0.1:7860"

requirements-test.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
pytest-base-url~=2.0
2+
pytest-cov~=4.0
3+
pytest~=7.3

test/basic_features/__init__.py

Whitespace-only changes.

test/basic_features/extras_test.py

-56
This file was deleted.

test/basic_features/img2img_test.py

-68
This file was deleted.

test/basic_features/txt2img_test.py

-82
This file was deleted.

0 commit comments

Comments
 (0)