Skip to content

Commit

Permalink
Ugly fix for a pytest issue
Browse files Browse the repository at this point in the history
  • Loading branch information
edyan committed May 22, 2021
1 parent 59a04bc commit 057b19e
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions tests/cli_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from click.testing import CliRunner
from stakkr.docker_actions import get_client as docker_client, _container_in_network
from stakkr.cli import stakkr
from stakkr.proxy import Proxy

BASE_DIR = os.path.abspath(os.path.dirname(__file__))
sys.path.insert(0, BASE_DIR + '/../')
Expand All @@ -19,6 +20,13 @@ class CliTest(unittest.TestCase):
def capfd(self, capfd):
self.capfd = capfd

# see https://github.com/pytest-dev/pytest/issues/5502
@pytest.fixture(autouse=True)
def capture_wrap(self):
sys.stderr.close = lambda *args: None
sys.stdout.close = lambda *args: None
yield

def test_aliases(self):
exec_cmd(self.cmd_base + ['-c', BASE_DIR + '/static/config_aliases.yml', 'start'])

Expand Down Expand Up @@ -343,16 +351,17 @@ def test_services_add_service_from_url(self):
self.assertRegex(res['stdout'], r'.*Package.*databases.*installed successfully')
self.assertIs(res['status'], 0)

def setUpClass():
@classmethod
def setUpClass(cls):
"""Clean containers and services directory"""
from docker import client
from docker.errors import NotFound
from docker.errors import NotFound, APIError
cts = client.from_env().containers.list(all=True)
for ct in cts:
try:
ct.stop()
ct.remove(v=True, force=True)
except NotFound:
except (NotFound, APIError):
pass

cli = CliTest()
Expand All @@ -362,7 +371,8 @@ def setUpClass():
exec_cmd(cli.cmd_base + ['services-add', 'php'])
exec_cmd(cli.cmd_base + ['services-add', 'emails'])

def tearDownClass():
@classmethod
def tearDownClass(cls):
cli = CliTest()

exec_cmd(cli.cmd_base + ['stop'])
Expand All @@ -377,7 +387,6 @@ def tearDownClass():
exec_cmd(cli.cmd_base + ['services-add', 'emails'])

def _proxy_start_check_not_in_network(self):
from stakkr.proxy import Proxy
# First start Proxy to verify it'll be added in the network
stop_remove_container('proxy_stakkr')
Proxy().start()
Expand Down

0 comments on commit 057b19e

Please sign in to comment.