I used to have a very customized Emacs configuration with lot of packages, hotkeys, custom variables and a lot of things. Then, one day, I met Spacemacs. Basically, it is exactly what I had but better and maintained by other people.
We have a very custom way to run tests:
- use a specific virtualenv
- we run the test inside docker
- we use a docker-compose wrapper made with invoke
- we use tox to run pytest
- filepath of test file in host does not exist in the container
Basically, we need a very specific command to run the test and, of course that pytest.el won't know what to do here, and it will fail even trying to guess hard. So, I needed a way to customize what is the command that pytest.el is going to execute. Fortunately, the author already thought on some variables that helped me to make me happy -but there is one function that can't be replaced using a customizable variable. I had to override it.
Define the variables I need in .dir-locals.el, so it only affects the project I want
Override pytest.el pytest-cmd-format function
;; .emacs.d/private/local/docker-tox-pytest.el (defcustom pytest-remove-path "" "Path to remove from pytest test-names variable") (with-eval-after-load 'pytest (defun pytest-cmd-format (format-string working-directory test-runner command-flags test-names) "Override default function to remove local path." (format format-string working-directory test-runner command-flags (replace-regexp-in-string pytest-remove-path "" test-names))) )
Load my docker-tox-pytest.el file from Spacemacs
Now a simple SPC m t t somewhere in the function that I want to test will call the command I need and will execute only that test.