[英]Is it possible to run a single doctest in Django using “manage.py test”
In my Django app, I have a mix of doctests (defined in models.py and views.py) and unit tests (defined in tests.py. I can invoke an individual unit test by doing: 在我的Django应用程序中,我有各种doctests(在models.py和views.py中定义)和单元测试(在tests.py中定义。我可以通过执行以下操作来调用单个单元测试:
manage.py test app.TestCase
However, this doesn't seem to work for the doctests. 但是,这似乎不适用于doctests。 Is there some way to run a single doctest (defined in models.py or views.py)?
有没有办法运行单个doctest(在models.py或views.py中定义)?
I think the way python doctests work is to simply run all doctests in a module in the same interpreter instance. 我认为python doctests的工作方式是在同一个解释器实例中运行模块中的所有doctests。
I doubt that manage.py can alter that basic behavior of python doctests. 我怀疑manage.py可以改变python doctests的基本行为。
I posted a small script that lets you run doctests in a specific file or module in your project. 我发布了一个小脚本,允许您在项目中的特定文件或模块中运行doctests。 Running doctests from a specific file or module: LINK .
从特定文件或模块运行doctests: LINK 。
It makes sure that the correct testing environment is loaded (emulating what manage.py test does). 它确保加载正确的测试环境(模拟manage.py测试的作用)。 Hope this helps.
希望这可以帮助。
试试这种方式:
python -m doctest views.py
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.