Skip to content

Commit

Permalink
Show error message when keywords expression contains a syntax error (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
nawatts authored Oct 6, 2021
1 parent f1b01e2 commit 536e9d1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
13 changes: 11 additions & 2 deletions nox/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import ast
import importlib.machinery
import io
import json
Expand Down Expand Up @@ -150,9 +151,17 @@ def filter_manifest(
manifest.filter_by_python_interpreter(global_config.pythons)

# Filter by keywords.
# This function never errors, but may cause an empty list of sessions
# (which is an error condition later).
if global_config.keywords:
try:
ast.parse(global_config.keywords, mode="eval")
except SyntaxError:
logger.error(
"Error while collecting sessions: keywords argument must be a Python expression."
)
return 3

# This function never errors, but may cause an empty list of sessions
# (which is an error condition later).
manifest.filter_by_keywords(global_config.keywords)

# Return the modified manifest.
Expand Down
9 changes: 9 additions & 0 deletions tests/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,15 @@ def test_filter_manifest_keywords():
assert len(manifest) == 2


def test_filter_manifest_keywords_syntax_error():
config = _options.options.namespace(
sessions=(), pythons=(), keywords="foo:bar", posargs=[]
)
manifest = Manifest({"foo_bar": session_func, "foo_baz": session_func}, config)
return_value = tasks.filter_manifest(manifest, config)
assert return_value == 3


def test_honor_list_request_noop():
config = _options.options.namespace(list_sessions=False)
manifest = {"thing": mock.sentinel.THING}
Expand Down

0 comments on commit 536e9d1

Please sign in to comment.