我正在寻找一种方法来使用标记来标记 pytest 测试,具体取决于此测试使用的固定装置。
我想用它来根据测试使用的功能来过滤测试。例如:使用“database_connection”装置的测试应自动标记为“database”。这样,我可以根据数据库凭据是否在手,包含或排除所有此类测试。
这就是我目前所拥有的:
def pytest_configure(config):
"""Register hook to extend the list of available markers."""
config.addinivalue_line("markers", "database: mark test that need a database connection.")
def pytest_collection_modifyitems(config, items): # pylint: disable=unused-argument
"""Register hook to map used fixtures to markers."""
for item in items:
if "database_connection" in item.fixturenames:
database_marker = pytest.mark.database()
item.add_marker(database_marker)
@pytest.fixture
def database_connection():
"""Fixture providing a database connection."""
Run Code Online (Sandbox Code Playgroud)
这正是我想要的方式,但我不喜欢必须维护从夹具到标记的映射与夹具本身分开。我想做的是用标记来装饰固定装置,这些标记应该在使用它们的所有测试上设置。它应该看起来像这样:
def pytest_configure(config):
"""Register hook to extend the list of available markers."""
config.addinivalue_line("markers", "database: mark test that need a database connection.") …
Run Code Online (Sandbox Code Playgroud) 在我的研究中,我发现在 Python 3 中这三种类型的类定义是同义词:
class MyClass:
pass
class MyClass():
pass
class MyClass(object):
pass
Run Code Online (Sandbox Code Playgroud)
但是,我无法找出推荐哪种方式。我应该使用哪一个作为最佳实践?
我想,以反映所有可用的本地存储库refs
,包括refs/notes/*
.但是,未按预期克隆注释.
要重现该问题,请在空目录中执行以下命令:
$ git init repo && cd repo
$ git commit --allow-empty -m 'initial commit'
$ git notes add -m 'Initial commit on empty repo' HEAD
$ git clone --mirror .git ../mirror
Run Code Online (Sandbox Code Playgroud)
获取refs之间的差异显示notes
镜像存储库中缺少:
$ diff repo/.git/refs mirror/refs
Common subdirectories: repo/.git/refs/heads and mirror/refs/heads
Common subdirectories: repo/.git/refs/tags and mirror/refs/tags
Only in repo/.git/refs: notes
Run Code Online (Sandbox Code Playgroud)
git -C mirror fetch
即使在fetch = +refs/*:refs/*
中指定,也不会获取注释mirror/config
.
现在的问题是:我有什么遗失的东西吗?我正在使用git 2.3.0