現在、テストをマークしてから、引数を使用して実行する (または実行しない) ことができ-m
ます。ただし、すべてのテストが最初に収集され、その後に選択が解除されます
以下の例では、まだ 8 つすべてが収集されていますが、4 つが実行され、4 つが選択解除されています。
============================= test session starts ==============================
platform win32 -- Python 2.7.3 -- pytest-2.3.2 -- C:\Python27\python.exe
collecting ... collected 8 items
test_0001_login_logout.py:24: TestLoginLogout.test_login_page_ui PASSED
test_0001_login_logout.py:36: TestLoginLogout.test_login PASSED
test_0001_login_logout.py:45: TestLoginLogout.test_default_admin_has_users_folder_page_loaded_by_default PASSED
test_0001_login_logout.py:49: TestLoginLogout.test_logout PASSED
==================== 4 tests deselected by "-m 'undertest'" ====================
================== 4 passed, 4 deselected in 1199.28 seconds ===================
質問:マークされた/マークされていないテストをまったく収集しないことは可能ですか?
問題は次のとおりです。
1)データベースにすでにいくつかのアイテム( my deviceなど)とそれが持っているコードがある場合、いくつかのテストを使用しています:
@pytest.mark.device
class Test1_Device_UI_UnSelected(SetupUser):
#get device from the database
device = Devices.get_device('t400-alex-win7')
@classmethod
@pytest.fixture(scope = "class", autouse = True)
def setup(self):
...
デバイステストを明示的に除外してテストを実行します。ただし、まだ実行中py.test -m "not device"
であるため、収集中にエラーが発生します。device = Devices.get_device('t400-alex-win7')
time_demanding
2)約 400 の生成されたテストがあるため、一部のテストはマークされています。これらのテストの生成にも時間がかかります。これらのテストは一般的なテストから除外しますが、それらは生成および収集されてから選択解除されます <- しばらくお待ちください。
(1)の問題の解決策があることは知っています-pytest.fixturesを使用してテストに渡しますが、 PyDevが提供するオートコンプリートが本当に好きです。
timedemanding
クラスは次のとおりです。
import pytest
#... other imports
def admin_rights_combinations(admin, containing = ["right"]):
'''
Generate all possible combinations of admin rights settings depending
on "containing" restriction
'''
rights = [right for right in admin.__dict__.iterkeys() if any(psbl_match in right for psbl_match in containing)]
total_list = []
l = []
for right in rights: #@UnusedVariable
l.append([True, False])
for st_of_values in itertools.product(*l):
total_list.append(dict(zip(rights, st_of_values)))
return total_list
@pytest.mark.timedemanding
class Test1_Admin_Rights_Access(SetupUser):
user = UserFactory.get_user("Admin Rights Test")
user.password = "RightsTest"
folder = GroupFolderFactory.get_folder("Folders->Admin Rights Test Folder")
group = GroupFolderFactory.get_group("Folders->Admin Rights Test Group")
admin = UserFactory.get_admin("Admin Rights Test")
@classmethod
@pytest.fixture(scope = "class", autouse = True)
def setup(self):
...
@pytest.mark.parametrize("settings", admin_rights_combinations(admin, containing=['right_read',
'right_manage_folders',
'right_manage_groups']))
def test_admin_rights_menus(self, base_url,settings):
'''
test combination of admin rights and pages that are displayed with
this rights. Also verify that menu's that are available can be opened
'''
ご覧のとおり、pytest がヒット@pytest.mark.parametrize
するまでに、それが Class with にあることをすでに認識しているはず@pytest.mark.timedemanding
です。ただし、コレクションは引き続き発生します。