0

I am using emacs24 with python.el (package shipped by emacs)

My workflow is usually the following:

  1. Writing python code in my_code.py
  2. Writing tests in tests.py
  3. Execute tests from command line
  4. Goto step 1

I would like to start the tests.py from shell without leaving emacs (or opening a shell buffer), to see the results and go on coding.

So far I could only find the possibility to run the tests.py script in buffer (py-execute-buffer). In this case, the interpreter ignores the if __name__ == '__main__' condition. Also there is no way to pass command line arguments.

Is there a way to define so called run-configurations, i.e. "run file xy.py with n command line arguments and use the interpreter in path x/y/z" ?

1
  • I would put the command that you use to run tests in a Makefile. And use github.com/abo-abo/helm-make to quickly select a make target without leaving the buffer. Commented Mar 2, 2014 at 15:41

1 Answer 1

1

A general option is use to the compile command, you can pass it exact command you want to execute and it run the command and output the results in separate buffer. The errors are clickable so clicking on them will take you the test that failed. If can also wrap this in a custom command so that you will be able to run tests with just a keypress, but this of course depends on you workflow.

If you are using nose for testing then have a look at nosemacs which allows you to run nose tests from emacs.

Sign up to request clarification or add additional context in comments.

4 Comments

Thanks a lot. I had a look into their code and it seems to use the compile command. Is there a convenient way to define multiple compile commands? (Like run configuration for tests and one for a call with parameters?)
I am not sure I understood you right, so this this maybe off the mark. When you do M-x compile it does ask for the commands to execute. Are you asking whether you can define custom commands so that you can directly run a given test_file (without entering the parameters again)?
Exactly, or something like different M-x compile and then in prompt enter runconf or testconf or create-egg ...
That is can be easy to hard to define in elisp, depending on you proficiency with elisp. I can help you if you give me an example of what you want to do in runconf, testconf. A template of such function is (defun my-custom-command () (interactive) (compile "<your-shell-command>"))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.