Skip to content
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

e2eテストのTestClientをfixtureにする #737

Merged

Conversation

Hiroshiba
Copy link
Member

@Hiroshiba Hiroshiba commented Aug 26, 2023

内容

e2eテストのTestClientインスタンスをfixtureにしてみました。

fixtureにする利点はいくつかあります。

後々製品版のコアを使うようにする時などに外部から製品版コアのパスを指定しないといけないのですが、fixtureを使えばpytestに乗っかる形になり、コマンドからオプションを渡すのが便利だったりします。

他にもテスト内の全てのセッションでインスタンスを1つだけ作るのか、テストごとにインスタンスを作成するのかなどを分けたりすることもできるようになるので便利だったりします。

関連 Issue

スクリーンショット・動画など

その他

@Hiroshiba Hiroshiba requested a review from a team as a code owner August 26, 2023 03:03
@Hiroshiba Hiroshiba requested review from y-chan and removed request for a team August 26, 2023 03:03
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ファイルをムーブしただけ

Comment on lines +6 to 9
def test_fetch_version_success(client: TestClient):
response = client.get("/version")
assert response.status_code == 200
assert response.json() == __version__
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stmtk1 こんな感じで、引数でclientを取得できます!
以前のimportするコードとほとんど変わらないかなと・・・!

@Hiroshiba Hiroshiba changed the title e2eテストのsessionをfixtureにする e2eテストのTestClientをfixtureにする Aug 26, 2023
@github-actions
Copy link

github-actions bot commented Aug 26, 2023

Coverage Result

Resultを開く
Name Stmts Miss Cover
run.py 433 285 coverage-34%
voicevox_engine/init.py 1 0 coverage-100%
voicevox_engine/acoustic_feature_extractor.py 75 0 coverage-100%
voicevox_engine/cancellable_engine.py 85 66 coverage-22%
voicevox_engine/dev/core/init.py 2 0 coverage-100%
voicevox_engine/dev/core/mock.py 27 12 coverage-56%
voicevox_engine/dev/synthesis_engine/init.py 2 0 coverage-100%
voicevox_engine/dev/synthesis_engine/mock.py 36 2 coverage-94%
voicevox_engine/downloadable_library.py 93 5 coverage-95%
voicevox_engine/engine_manifest/EngineManifest.py 34 0 coverage-100%
voicevox_engine/engine_manifest/EngineManifestLoader.py 12 0 coverage-100%
voicevox_engine/engine_manifest/init.py 3 0 coverage-100%
voicevox_engine/full_context_label.py 162 3 coverage-98%
voicevox_engine/kana_parser.py 86 1 coverage-99%
voicevox_engine/metas/Metas.py 33 0 coverage-100%
voicevox_engine/metas/MetasStore.py 29 12 coverage-59%
voicevox_engine/metas/init.py 2 0 coverage-100%
voicevox_engine/model.py 160 9 coverage-94%
voicevox_engine/mora_list.py 4 0 coverage-100%
voicevox_engine/morphing.py 70 46 coverage-34%
voicevox_engine/part_of_speech_data.py 5 0 coverage-100%
voicevox_engine/preset/Preset.py 12 0 coverage-100%
voicevox_engine/preset/PresetError.py 2 0 coverage-100%
voicevox_engine/preset/PresetManager.py 81 2 coverage-98%
voicevox_engine/preset/init.py 4 0 coverage-100%
voicevox_engine/setting/Setting.py 11 0 coverage-100%
voicevox_engine/setting/SettingLoader.py 19 0 coverage-100%
voicevox_engine/setting/init.py 3 0 coverage-100%
voicevox_engine/synthesis_engine/init.py 5 0 coverage-100%
voicevox_engine/synthesis_engine/core_wrapper.py 201 146 coverage-27%
voicevox_engine/synthesis_engine/make_synthesis_engines.py 59 30 coverage-49%
voicevox_engine/synthesis_engine/synthesis_engine.py 130 11 coverage-92%
voicevox_engine/synthesis_engine/synthesis_engine_base.py 67 9 coverage-87%
voicevox_engine/user_dict.py 144 11 coverage-92%
voicevox_engine/utility/init.py 5 0 coverage-100%
voicevox_engine/utility/connect_base64_waves.py 37 0 coverage-100%
voicevox_engine/utility/core_version_utility.py 8 1 coverage-88%
voicevox_engine/utility/mutex_utility.py 10 0 coverage-100%
voicevox_engine/utility/path_utility.py 26 8 coverage-69%
TOTAL 2178 659 coverage-70%

Copy link
Member

@takana-v takana-v left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

自分の環境では、pytestだとrunがimportできずに落ちてしまいました。
(現在のmasterでは動作)
coverage run --omit=test/* -m pytestだときちんと動作しました。

エラーログ
$ pytest
===================================================================================================== test session starts ======================================================================================================
platform win32 -- Python 3.11.3, pytest-6.2.5, py-1.11.0, pluggy-1.2.0
rootdir: C:\Users\takana\Github\voicevox_engine
plugins: anyio-3.7.1
collected 0 items / 1 error

============================================================================================================ ERRORS ============================================================================================================ 
________________________________________________________________________________________________ ERROR collecting test session _________________________________________________________________________________________________ 
..\..\.pyenv\pyenv-win\versions\3.11.3\Lib\importlib\__init__.py:126: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
<frozen importlib._bootstrap>:1206: in _gcd_import
    ???
<frozen importlib._bootstrap>:1178: in _find_and_load
    ???
<frozen importlib._bootstrap>:1149: in _find_and_load_unlocked
    ???
<frozen importlib._bootstrap>:690: in _load_unlocked
    ???
venv\Lib\site-packages\_pytest\assertion\rewrite.py:170: in exec_module
    exec(co, module.__dict__)
test\e2e\conftest.py:5: in <module>
    from run import generate_app
E   ModuleNotFoundError: No module named 'run'
=================================================================================================== short test summary info ==================================================================================================== 
ERROR  - ModuleNotFoundError: No module named 'run'
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 
======================================================================================================= 1 error in 0.26s =======================================================================================================

test/e2e/conftest.py Outdated Show resolved Hide resolved
@Hiroshiba
Copy link
Member Author

Hiroshiba commented Aug 30, 2023

@takana-v レビューありがとうございます!!!

自分の環境では、pytestだとrunがimportできずに落ちてしまいました。
(現在のmasterでは動作)
coverage run --omit=test/* -m pytestだときちんと動作しました。

pythonはデフォルトで実行ディレクトリをPYTHONPATHに追加しないのでrunのインポートに失敗したのかなと思います!
自分は無意識のうちにPYTHONPATH=. pytestで実行していました。

実行ディレクトリをPYTHONPATHに追加する方法として、pyproject.tomlにpythonpathを追加する方法がありそうなのですが、なんかうまく動きませんでした。。

python -m pytest

だとpythonの仕様?で自動的に実行ディレクトリがimport対象のパスに追加されるらしいので、とりあえずこの方法をリードミーで案内してみました・・・!

Copy link
Member

@y-chan y-chan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTMです!
マージします!
(気づかずお遅くなってしまってすみません...!)

@y-chan y-chan merged commit 2b9e234 into VOICEVOX:master Sep 15, 2023
3 checks passed
@Hiroshiba Hiroshiba deleted the e2eテストのsessionをfixtureにする branch September 15, 2023 05:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants