Everything is inside a docker container. Tox works fine separately inside docker. What I'm trying to do is to add Tox to the pre-commit hook to run it for files with changes to be committed.
.pre-commit-config.yaml
- repo: local
hooks:
- id: tox-project
name: tox
entry: tox
language: system
types: [python]
args: [-c, path_inside_docker/tox.ini,--workdir=path_inside_docker, -e, "fix,pylint,[other_tests]"]
When tox runs as a part of a pre-commit hook (defined as above), it generates an error that refers to the file with changes that I want to commit:
tox......................................................................Failed
- hook id: tox-project
- exit code: 2
usage: tox [-h] [--colored {yes,no}] [-v | -q] [--exit-and-dump-after seconds] [-c file]
[--workdir dir] [--root dir] [--runner {virtualenv}] [--version] [--no-provision [REQ_JSON]]
[--no-recreate-provision] [-r] [-x OVERRIDE]
{run,r,run-parallel,p,depends,de,list,l,devenv,d,config,c,quickstart,q,exec,e,legacy,
le} ...
tox: error: unrecognized arguments: path/to/file/to/be/commited/main.py hint: if you tried to pass
arguments to a command use -- to separate them from tox ones
What I tried:
1st solution. To add "--" to args for tox, to pass files from commit. Which I found here: Add -- as argument for tox
args: [-c, path_inside_docker/tox.ini,--workdir=path_inside_docker, -e,"fix,pylint,[other_tests]",--]
Now tox runs as a hook, but it doesn't work properly. Hook pass tox with success, and commit is done. But the tox is not generating any results as supposed to (when the same file is tested by a separate tox outside hook, it generates a list of errors).
2nd solution. Turn off passing filenames.
I've found this solution for a similar issue, solved by: pass_filenames: false. I tried this as well. But then tox is (as I understand) not getting any files from the commit to process and finish everything with success - again not generating any results that it suppose to generate.
Any ideas?