Skip to content

nox.options.keywords unexpected behaviour #988

@Kamforka

Description

@Kamforka

Current Behavior

The nox.options.keywords configuration option makes the nox command to error out when specified in noxfile.py

Expected Behavior

The noxfile.py's nox.options.keywords option should behave the same as the -k command line flag.

Steps To Reproduce

  1. With this noxfile.py:
import nox

nox.options.keywords = ["ci and not test"]


@nox.session(tags=["ci", "lint"])
def style(session: nox.Session):
    """Run style checks."""
    print("running style checks...")


@nox.session(tags=["ci", "test"])
def test(session: nox.Session):
    """Run integration tests with pytest."""
    print("running tests...")
  1. Run:
    nox -l
  2. See error:
Traceback (most recent call last):
  File "/home/ubuntu/projects/mypkg/venv/bin/nox", line 8, in <module>
    sys.exit(main())
             ~~~~^^
  File "/home/ubuntu/projects/mypkg/venv/lib/python3.13/site-packages/nox/_cli.py", line 219, in main
    exit_code = execute_workflow(args)
  File "/home/ubuntu/projects/mypkg/venv/lib/python3.13/site-packages/nox/_cli.py", line 53, in execute_workflow
    return workflow.execute(
           ~~~~~~~~~~~~~~~~^
        global_config=args,
        ^^^^^^^^^^^^^^^^^^^
    ...<10 lines>...
        ),
        ^^
    )
    ^
  File "/home/ubuntu/projects/mypkg/venv/lib/python3.13/site-packages/nox/workflow.py", line 61, in execute
    return_value = function_(*args, **kwargs)
  File "/home/ubuntu/projects/mypkg/venv/lib/python3.13/site-packages/nox/tasks.py", line 231, in filter_manifest
    ast.parse(global_config.keywords, mode="eval")
    ~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/ubuntu/.pyenv/versions/3.13.3/lib/python3.13/ast.py", line 54, in parse
    return compile(source, filename, mode, flags,
                   _feature_version=feature_version, optimize=optimize)
TypeError: compile() arg 1 must be a string, bytes or AST object

Environment

- OS: Ubuntu 20.04
- Python: 3.13.3
- Nox: 2025.5.1

Anything else?

On the other hand the command nox -l -k "ci and not test" works as expected and outputs the below:

Sessions defined in /home/ubuntu/projects/mypkg/noxfile.py:

* style -> Run style checks.
- test -> Run integration tests with pytest.

sessions marked with * are selected, sessions marked with - are skipped.

Additionally in the noxfile.py I other values:

nox.options.keywords = "ci and not test"  # fails with: ValueError: ("not_ validator child '<instance_of validator for type <class 'str'>>' did not raise a captured error", Attribute(name='keywords', default=NOTHING, validator=<optional validator for <deep_iterable validator for <not_ validator wrapping <instance_of validator for type <class 'str'>>, capturing (<class 'ValueError'>, <class 'TypeError'>)> iterables of <instance_of validator for type <class 'str'>>> or None>, repr=True, eq=True, eq_key=None, order=True, order_key=None, hash=None, init=True, metadata=mappingproxy({}), type='None | Sequence[str]', converter=None, kw_only=True, inherited=False, on_setattr=None, alias='keywords'), <instance_of validator for type <class 'str'>>, 'ci and not test', (<class 'ValueError'>, <class 'TypeError'>))
nox.options.keywords = ["ci", "and", "not", "test"]  # fails with: TypeError: compile() arg 1 must be a string, bytes or AST object

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions