155

test/functionalディレクトリにたくさんのテストがあるPylons1.0アプリがあります。奇妙なテスト結果が得られたので、1つのテストだけを実行したいと思います。ノーズのドキュメントには、コマンドラインでテスト名を渡すことができるはずだと書かれていますが、何をしてもImportErrorsが発生します

例えば:

nosetests -x -s sometestname

与える:

Traceback (most recent call last):
  File "/home/ben/.virtualenvs/tsq/lib/python2.6/site-packages/nose-0.11.4-py2.6.egg/nose/loader.py", line 371, in loadTestsFromName
   module = resolve_name(addr.module)
  File "/home/ben/.virtualenvs/tsq/lib/python2.6/site-packages/nose-0.11.4-py2.6.egg/nose/util.py", line 334, in resolve_name
   module = __import__('.'.join(parts_copy))
ImportError: No module named sometestname

同じエラーが発生します

nosetests -x -s appname.tests.functional.testcontroller

正しい構文は何ですか?

4

6 に答える 6

237

nosetests appname.tests.functional.test_controller動作するはずです。ファイルの名前はtest_controller.pyです。

特定のテストクラスとメソッドを実行するには、形式のパスを使用しますmodule.path:ClassNameInFile.method_name。つまり、モジュール/ファイルのパスとファイル内のオブジェクトをコロンで区切ります。module.pathファイルへの相対パスです(例tests/my_tests.py:ClassNameInFile.method_name)。

于 2010-09-13T22:09:03.837 に答える
47

Nosetests 1.3.0を使用している私にとって、これらのバリアントは機能しています(ただし__init__.py、テストフォルダーにあることを確認してください)。

nosetests [options] tests.ui_tests
nosetests [options] tests/ui_tests.py
nosetests [options] tests.ui_tests:TestUI.test_admin_page

モジュール名とクラス名の間の単一のコロンに注意してください。

于 2013-06-26T19:14:30.210 に答える
2

「.py」ファイル拡張子を追加する必要があります。つまり、

r'/path_to/my_file.py:' +  r'test_func_xy'

これは、ファイルにクラスがないためかもしれません。なしで.py、鼻は不平を言っていました:

ファイル/path_to/ my_fileで呼び出し可能なtest_func_xyが見つかりません:ファイルはPythonモジュールではありません

そして、これは私が__init__.pyフォルダにありますが/path_to/

于 2015-03-20T11:33:02.957 に答える
0

以前の回答に基づいて、この小さなスクリプトを作成しました。

#!/usr/bin/env bash

# 
# Usage:
# 
#     ./noseTest <filename> <method_name>
# 
# e.g.:
# 
#     ./noseTest test/MainTest.py mergeAll
#     
# It is assumed that the file and the test class have the _same name_ 
# (e.g. the test class `MainTest` is defined in the file `MainTest.py`).
# If you don't follow this convention, this script won't work for you.
#

testFile="$1"
testMethod="$2"

testClass="$(basename "$testFile" .py)"

nosetests "$testFile:$testClass.test_$testMethod"
于 2017-07-31T19:52:32.890 に答える
0

以下は私にとってうまくいきました:

nosetests test_file.py:method_name

私のテストはクラスにないことに注意してください。テストメソッドは1つのファイルに含まれていました。

于 2019-05-02T14:48:09.690 に答える
0

ノーズテスト1.3.7の場合、次のことを行う必要があります。

nosetests --tests=tests.test_something.py,tests.test_something_else.py

于 2021-01-08T13:02:58.497 に答える