Page Menu
Home
Software Heritage
Search
Configure Global Search
Log In
Files
F9345323
D2330.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
3 KB
Subscribers
None
D2330.diff
View Options
diff --git a/conftest.py b/conftest.py
--- a/conftest.py
+++ b/conftest.py
@@ -1,6 +1,20 @@
+import pytest
from hypothesis import settings
+from swh.core.cli import swh as _swhmain
+
# define tests profile. Full documentation is at:
# https://hypothesis.readthedocs.io/en/latest/settings.html#settings-profiles
settings.register_profile("fast", max_examples=5, deadline=5000)
settings.register_profile("slow", max_examples=20, deadline=5000)
+
+
+@pytest.fixture
+def swhmain():
+ """Yield an instance of the main `swh` click command that cleans the added
+ subcommands up on teardown."""
+ commands = _swhmain.commands.copy()
+ aliases = _swhmain.aliases.copy()
+ yield _swhmain
+ _swhmain.commands = commands
+ _swhmain.aliases = aliases
diff --git a/swh/core/db/tests/test_cli.py b/swh/core/db/tests/test_cli.py
--- a/swh/core/db/tests/test_cli.py
+++ b/swh/core/db/tests/test_cli.py
@@ -2,7 +2,6 @@
from click.testing import CliRunner
-from swh.core.cli import swh as swhmain
from swh.core.cli.db import db as swhdb
@@ -28,7 +27,7 @@
'''
-def test_swh_help():
+def test_swh_help(swhmain):
swhmain.add_command(swhdb)
runner = CliRunner()
result = runner.invoke(swhmain, ['-h'])
@@ -49,7 +48,7 @@
'''
-def test_swh_db_help():
+def test_swh_db_help(swhmain):
swhmain.add_command(swhdb)
runner = CliRunner()
result = runner.invoke(swhmain, ['db', '-h'])
diff --git a/swh/core/tests/test_cli.py b/swh/core/tests/test_cli.py
--- a/swh/core/tests/test_cli.py
+++ b/swh/core/tests/test_cli.py
@@ -7,8 +7,6 @@
from click.testing import CliRunner
import pytest
-from swh.core.cli import swh as swhmain
-
help_msg = '''Usage: swh [OPTIONS] COMMAND [ARGS]...
@@ -29,7 +27,7 @@
'''
-def test_swh_help():
+def test_swh_help(swhmain):
runner = CliRunner()
result = runner.invoke(swhmain, ['-h'])
assert result.exit_code == 0
@@ -40,7 +38,7 @@
assert result.output.startswith(help_msg)
-def test_command():
+def test_command(swhmain):
@swhmain.command(name='test')
@click.pass_context
def swhtest(ctx):
@@ -52,7 +50,7 @@
assert result.output.strip() == 'Hello SWH!'
-def test_loglevel_default(caplog):
+def test_loglevel_default(caplog, swhmain):
@swhmain.command(name='test')
@click.pass_context
def swhtest(ctx):
@@ -66,7 +64,7 @@
assert result.output.strip() == '''Hello SWH!'''
-def test_loglevel_error(caplog):
+def test_loglevel_error(caplog, swhmain):
@swhmain.command(name='test')
@click.pass_context
def swhtest(ctx):
@@ -79,7 +77,7 @@
assert result.output.strip() == '''Hello SWH!'''
-def test_loglevel_debug(caplog):
+def test_loglevel_debug(caplog, swhmain):
@swhmain.command(name='test')
@click.pass_context
def swhtest(ctx):
@@ -120,7 +118,7 @@
yield str(tmp_path / 'log_config.yml')
-def test_log_config(caplog, log_config_path):
+def test_log_config(caplog, log_config_path, swhmain):
@swhmain.command(name='test')
@click.pass_context
def swhtest(ctx):
@@ -145,7 +143,7 @@
])
-def test_log_config_log_level_interaction(caplog, log_config_path):
+def test_log_config_log_level_interaction(caplog, log_config_path, swhmain):
@swhmain.command(name='test')
@click.pass_context
def swhtest(ctx):
@@ -170,7 +168,7 @@
])
-def test_aliased_command():
+def test_aliased_command(swhmain):
@swhmain.command(name='canonical-test')
@click.pass_context
def swhtest(ctx):
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, Jul 3, 3:18 PM (5 d, 18 h ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3222238
Attached To
D2330: Make sure that cli tests don't leave subcommands hanging
Event Timeline
Log In to Comment