reubano / pygogo

A Python logging library with superpowers
MIT License
281 stars 20 forks source link

tests/test.py fails with invalid syntax #23

Open nieder opened 1 year ago

nieder commented 1 year ago

Testing 1.3.0, running tests fails like this:

$ PYTHONPATH=/sw/build.build/pygogo-py38-1.3.0-1/pygogo-1.3.0/build/lib /sw/bin/python3.8 tests/test.py
Script result: /sw/build.build/pygogo-py38-1.3.0-1/pygogo-1.3.0/bin/gogo --help
  return code: 1
-- stderr: --------------------
Traceback (most recent call last):
  File "/sw/build.build/pygogo-py38-1.3.0-1/pygogo-1.3.0/bin/gogo", line 13, in <module>
    from pygogo import main
  File "/sw/build.build/pygogo-py38-1.3.0-1/pygogo-1.3.0/build/lib/pygogo/__init__.py", line 49, in <module>
    from . import formatters, handlers, utils
  File "/sw/build.build/pygogo-py38-1.3.0-1/pygogo-1.3.0/build/lib/pygogo/formatters.py", line 405
    logging.DEBUG: f"{debug_color} {self._fmt} {RESET}",
                                                      ^
SyntaxError: invalid syntax

Traceback (most recent call last):
  File "tests/test.py", line 98, in <module>
    main(script, tests)
  File "tests/test.py", line 44, in main
    result = env.run(command, cwd=p.abspath(p.dirname(p.dirname(__file__))))
  File "/sw/lib/python3.8/site-packages/scripttest.py", line 273, in run
    result.assert_no_error(quiet)
  File "/sw/lib/python3.8/site-packages/scripttest.py", line 426, in assert_no_error
    raise AssertionError(
AssertionError: Script returned code: 1

/sw/bin/nosetests3.8 -xv finished fine with no errors in 57 tests. This failure happens with py3.8, 3.9, and 3.10. This is macOS 10.14.5, but I don't think this would matter given the error type.

nieder commented 1 year ago

The issue here is that bin/gogo uses #!/usr/bin/env python (which is often python-2.7) even when told to use a specific python. pygogo/main.py also does not change the python interpreter to use. And so the test fails because gogo doesn't inherit the python3.8 (in my example) call that launched the tests.

Changing the #! line to an explicit python interpreter makes all tests pass.