Pylons

2010-09-13 15 views
133

'da Nose ile tek bir testi nasıl çalıştırırım Test/functional dizininde bir grup testle Pylons 1.0 uygulamasına sahibim. Garip test sonuçları alıyorum ve sadece tek bir test yapmak istiyorum. burun belgelerine komut satırında bir test adına geçmek mümkün olacağını söylüyor ama ne olursa olsun ben ÖrneğinPylons

ne ImportErrors olsun:

nosetests -x -s sometestname 

verir:

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 

doğru synt nedir

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

için aynı hatayı alıyorum balta? Dosyaya test_controller.py adı verilen yerlerde

cevap

206

nosetests appname.tests.functional.test_controller çalışmalıdır.

Belirli bir sınama sınıfı ve yöntemi çalıştırmak için, module.path:ClassNameInFile.method_name formunun bir yolunu kullanın; bu, modül/dosya yolunu ve dosya içindeki nesneleri ayıran iki nokta üst üste sahip bir kolon ile. module.path, dosyanın göreli yolu (ör. tests/my_tests.py:ClassNameInFile.method_name). Benim için

+1

Ahhh, ben deneyin vermedi tek kombinasyonu: – Ben

+2

Her test bir test kontrol cihazında/modülünde çalışacaktır. Tek bir test metodu çalıştırmaya ne dersiniz? Appname.tests.functional.test_controller.name_of_test_method 'gibi bir şey. –

+66

Belirli bir test sınıfını ve yöntemini çalıştırmak için, 'module.path: ClassNameInFile.method_name' biçimindeki bir yolu kullanın; bu, modül/dosya yolunu ve dosya içindeki nesneleri ayıran iki nokta üst üste. –

42

kullanarak Nosetests 1.3.0 bu varyantlar çalışan (ancak testler klasöründe __init__.py olduğundan emin olun) vardır:

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

Not o modül adı ve sınıf adı arasındaki tek kolon.

+1

İkinci seçenek için teşekkürler, bash otomatik tamamlama yardımı ile kesinlikle en uygun olanı. –

+0

Sadece aradığım şey, teşekkürler! – radtek

+0

Parametreli testlerin (@ parameterized.expand işlevini kullananlar) çağrılması için bu sözdizimini kullanmanız gerektiğine dikkat etmelisiniz: test_file.py:ClassNameInFile.MethodName_TestNumber, burada TestNumber 1, 2, 3, ... 1 olabilir parametreli test başına – luca

2

Ben dosyada herhangi sınıfları yok çünkü

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

Belki de bu, yani ".py" dosya uzantısı eklemek zorunda.

Can't find callable test_func_xy in file /path_to/my_file: file is not a python module

Ve bu klasördeki /path_to/ bir __init__.py olmasına rağmen: .py olmadan , burun şikayetçi oldu.

#!/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" 
0

Ben önceki cevaplara bağlı bu küçük senaryoyu yazdı. *iç çekmek*. Teşekkürler!
İlgili konular