forked from Backblaze/B2_Command_Line_Tool
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Integration tests with different versions
- Loading branch information
1 parent
7f42f7f
commit e87b49e
Showing
7 changed files
with
100 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import sys | ||
|
||
import pytest | ||
|
||
|
||
@pytest.hookimpl | ||
def pytest_configure(config): | ||
config.addinivalue_line( | ||
"markers", | ||
"cli_version(from_version, to_version): run tests only on certain versions", | ||
) | ||
|
||
|
||
@pytest.fixture(autouse=True) | ||
def run_on_cli_version_handler(request, cli_int_version): | ||
""" | ||
Auto-fixture that allows skipping tests based on the CLI version. | ||
Usage: | ||
@pytest.mark.cli_version(1, 3) | ||
def test_foo(): | ||
# Test is run only for versions 1 and 3 | ||
... | ||
@pytest.mark.cli_version(from_version=2, to_version=5) | ||
def test_bar(): | ||
# Test is run only for versions 2, 3, 4 and 5 | ||
... | ||
Note that it requires the `cli_int_version` fixture to be defined. | ||
Both unit tests and integration tests handle it a little bit different, thus | ||
two different fixtures are provided. | ||
""" | ||
node = request.node.get_closest_marker('cli_version') | ||
if not node: | ||
return | ||
|
||
if node.args: | ||
if cli_int_version in node.args: | ||
# Run the test. | ||
return | ||
|
||
if node.kwargs: | ||
from_version = node.kwargs.get('from_version', 0) | ||
to_version = node.kwargs.get('to_version', sys.maxsize) | ||
|
||
if from_version <= cli_int_version <= to_version: | ||
# Run the test. | ||
return | ||
|
||
pytest.skip('Not supported on this CLI version') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters