I have just switched over to using PyCharm as my primary Python editor, and am curious to know how I can configure it so that every time I save a file, that the unit-test corresponding to the modified file will be run? (after poking around the documentation, I have not found a clear explanation of how to do this)
相关问题
- how to define constructor for Python's new Nam
- streaming md5sum of contents of a large remote tar
- How to get the background from multiple images by
- Evil ctypes hack in python
- Correctly parse PDF paragraphs with Python
Here is the way that I decided to accomplish my objective.
I use file watchers (
PyCharm->Preferences->File Watchers
) to monitor the python source files for modifications. Source files are located in a directory calledsrc
. For my purposes, each unit test is located in a directory that is parallel to thesrc
directory calledtest_src
, in which each filesrc/[file_name].py
will have an associated test file calledtest_src/test_[file_name].py
. Unit tests will by run bypy.test
.To accomplish this, I use the following setup in the File Watchers dialog:
I also unchecked "Immediate file synchronization" as I only want to run the unit tests when the file is saved.
Note that the "Scope" is used for specifying which files will be monitored.
When you run a unittest you get a new unittest window. In this window there's a button where you can toggle auto-testing on and off, see below. You can set the auto-test delay as well (look for the gear-icon in the same window.
You can try File Watchers plugin to execute task on files modification.
example config: