0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Adobe Substance 3D Painterでpytestを実行する方法

Posted at

環境

  • Windows
  • Adobe Substance 3D Painter 10.1.2
  • pytest 8.3.4

前提

Substance 3D PainterはコマンドラインからPythonを実行することが出来ないためPython Console (REPL) からpytestを実行する手段を考えます。

方法

Python Consoleから下記のようなコードで実行出来ます。

>>> import pytest
>>> pytest.main(args=["file_or_dir", "-p", "no:faulthandler"])

実行結果参考

説明

関数

Python Consoleから実行するためにまずpytest.exeが呼び出している関数を確認します。

エントリーポイント (__main__.py) を見ると

if __name__ == "__main__":
    raise SystemExit(pytest.console_main())

となっているので次に pytest.console_main() を確認します。

pytest.console.main()pytest/__init__.py から _pytest/config/__init__.py の console_main関数であることがわかります。

さらに _pytest/config/__init__.py の console_main関数を確認すると、コードとdocstringから
_pytest/config/__init__.py のmain関数を利用すればよいと判断できます。

また _pytest/config/__init__.py のmain関数については pytest/__init__.py__all__ の定義でパッケージからimportされるため、最終的に

>>> pytest.main(args=None, plugins=None)

を実行すればよいということがわかります。

引数

_pytest/config/__init__.py のmain関数のdocstringを読むと args にpytestのコマンドライン引数をリスト形式で渡せばよいことがわかります。

faulthandlerの無効化

Substance 3D Painterでは sys.__stderr__None であるためfaulthalderを無効化せずpytestを実行すると INTERNALERROR が発生します。

そのためfaulthandlerを無効化 (-p no:faulthandler) します。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?