-
Notifications
You must be signed in to change notification settings - Fork 168
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #574 from kdmukai/pyproject_toml_pytest_logging
[Bugfix] Restore log access in pytest
- Loading branch information
Showing
4 changed files
with
80 additions
and
32 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
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 |
---|---|---|
@@ -1,40 +1,50 @@ | ||
import logging | ||
import pytest | ||
import sys | ||
from unittest.mock import patch, call | ||
|
||
import pytest | ||
# Must import from base.py before any other SeedSigner dependency to mock out certain imports | ||
from base import BaseTest | ||
|
||
sys.path.insert(0,'src') | ||
from main import main | ||
|
||
|
||
@patch("main.Controller") | ||
def test_main__argparse__default(patched_controller): | ||
main([]) | ||
assert logging.root.level == logging.INFO | ||
assert logging.getLogger().getEffectiveLevel() == logging.INFO | ||
patched_controller.assert_has_calls( | ||
[call.get_instance(), call.get_instance().start()] | ||
) | ||
|
||
|
||
@patch("main.Controller") | ||
def test_main__argparse__enable_debug_logging(patched_controller): | ||
main(["--loglevel", "DEBUG"]) | ||
assert logging.root.level == logging.DEBUG | ||
assert logging.getLogger().getEffectiveLevel() == logging.DEBUG | ||
patched_controller.assert_has_calls( | ||
[call.get_instance(), call.get_instance().start()] | ||
) | ||
|
||
|
||
def test_main__argparse__invalid_arg(): | ||
with pytest.raises(SystemExit): | ||
main(["--invalid"]) | ||
|
||
|
||
@patch("main.Controller") | ||
def test_main__logging__writes_to_stderr(patched_controller, capsys): | ||
main([]) | ||
_, err = capsys.readouterr() | ||
assert "Starting SeedSigner" in err and "INFO" in err | ||
class TestMain(BaseTest): | ||
""" | ||
The `main.Controller` has to be patched / mocked out otherwise the virtual SeedSigner | ||
will just keep running and cause the test to hang. | ||
""" | ||
@patch("main.Controller") | ||
def test_main__argparse__default(self, patched_controller): | ||
main([]) | ||
assert logging.root.level == logging.INFO | ||
assert logging.getLogger().getEffectiveLevel() == logging.INFO | ||
patched_controller.assert_has_calls( | ||
[call.get_instance(), call.get_instance().start()] | ||
) | ||
|
||
|
||
@patch("main.Controller") | ||
def test_main__argparse__enable_debug_logging(self, patched_controller): | ||
main(["--loglevel", "DEBUG"]) | ||
assert logging.root.level == logging.DEBUG | ||
assert logging.getLogger().getEffectiveLevel() == logging.DEBUG | ||
patched_controller.assert_has_calls( | ||
[call.get_instance(), call.get_instance().start()] | ||
) | ||
|
||
|
||
def test_main__argparse__invalid_arg(self): | ||
with pytest.raises(SystemExit): | ||
main(["--invalid"]) | ||
|
||
|
||
@patch("main.Controller") | ||
def test_main__logging__writes_to_stderr(self, patched_controller, capsys): | ||
main([]) | ||
_, err = capsys.readouterr() | ||
assert "Starting SeedSigner" in err and "INFO" in err | ||
patched_controller.assert_has_calls( | ||
[call.get_instance(), call.get_instance().start()] | ||
) |