Skip to content

Commit

Permalink
fix nameko test command (nameko#750)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattbennett authored and Loic Jaquemet committed Feb 23, 2022
1 parent 02ba742 commit 727c4fa
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 1 deletion.
10 changes: 9 additions & 1 deletion nameko/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,12 @@ def test(args):
eventlet.monkey_patch() # noqa (code before rest of imports)

import pytest
pytest.main(list(args))
import sys

args = list(args)
args.extend(
["-W", "ignore:Module already imported:_pytest.warning_types.PytestWarning"]
)

exit_code = pytest.main(args)
sys.exit(int(exit_code))
57 changes: 57 additions & 0 deletions test/cli/test_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import subprocess
from textwrap import dedent

import pytest


def test_test_pass(tmpdir, capsys):

tmpdir.join('__init__.py')
testfile = tmpdir.join('test_test_pass.py')
testfile.write(dedent("""
def test_foo():
assert True
"""))

proc = subprocess.Popen(
["nameko", "test", testfile.strpath], stdout=subprocess.PIPE
)
proc.wait()
assert proc.returncode == 0


def test_test_fail(tmpdir, capsys):

tmpdir.join('__init__.py')
testfile = tmpdir.join('test_test_fail.py')
testfile.write(dedent("""
def test_foo():
assert False
"""))

proc = subprocess.Popen(
["nameko", "test", testfile.strpath], stdout=subprocess.PIPE
)
proc.wait()
assert proc.returncode == 1


def test_suppress_warning(tmpdir, capsys): # pragma: no cover

if tuple(map(int, pytest.__version__.split("."))) < (6, 1):
pytest.skip("-W flag ignored on older pytests")

tmpdir.join('__init__.py')
testfile = tmpdir.join('test_test_pass.py')
testfile.write(dedent("""
def test_foo():
assert True
"""))

proc = subprocess.Popen(
["nameko", "test", testfile.strpath], stdout=subprocess.PIPE
)
proc.wait()

out = "".join(map(bytes.decode, proc.stdout.readlines()))
assert "Module already imported so cannot be rewritten: nameko" not in out

0 comments on commit 727c4fa

Please sign in to comment.