Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix pytest commandline flags being parsed by Beeref #117

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ Fixed
crashes (by DarkDefender)
* Fixed a crash when pressing the crop shortcut while dragging an image
(by DarkDefender)
* Fix commandline arguments meant for pytest being parsed by BeeRef
(by DarkDefender)


Changed
Expand Down
13 changes: 7 additions & 6 deletions beeref/config/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,16 +80,17 @@ class CommandlineArgs:
_instance = None

def __new__(cls, *args, **kwargs):
if not cls._instance or kwargs.get('with_check'):
if not cls._instance:
cls._instance = super().__new__(cls)
return cls._instance

def __init__(self, with_check=False):
if not hasattr(self, '_args'):
if with_check:
self._args = parser.parse_args()
else:
self._args = parser.parse_known_args()[0]
if with_check:
self._args = parser.parse_args()
elif not hasattr(self, '_args'):
# Do not parse any flags from sys.argv unless speficially
# told to do so.
self._args = parser.parse_args([])

def __getattribute__(self, name):
if name == '_args':
Expand Down
8 changes: 6 additions & 2 deletions tests/config/test_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,13 @@ def test_command_line_args_singleton():
@patch('beeref.config.settings.parser.parse_args')
def test_command_line_args_with_check_forces_new_parsing(parse_mock):
args1 = CommandlineArgs()
parse_mock.assert_called_with([])
args2 = CommandlineArgs(with_check=True)
parse_mock.assert_called_once()
assert args1 is not args2
parse_mock.assert_called_with()
args3 = CommandlineArgs()
assert parse_mock.call_count == 2
assert args1 is args2
assert args2 is args3
CommandlineArgs._instance = None


Expand Down
Loading