在 PyCharm 中的运行配置之间快速切换

发布于 2024-11-19 11:47:52 字数 654 浏览 2 评论 0原文

我定期执行的两个操作是“运行我的测试”和“运行我的应用程序”。不幸的是,PyCharm 对两者使用相同的击键(Shift+F10,即“运行”),并且该击键使用我的“当前”运行/调试配置。我必须执行单独的步骤来更改配置,该步骤涉及从较长的列表中查找并选择正确的选项 - 并且还需要花时间考虑是否我需要切换配置。

由于我经常运行测试和应用程序(我对 Python 还比较陌生,所以我想经常检查以确保我没有破坏任何东西),这是相当麻烦的——尤其是因为我通常的模式是“运行测试,如果通过,则运行应用程序”,所以我一直在切换配置。

是否有更简单的方法来运行给定的配置?理想情况下,我希望能够将单个击键绑定到“选择并运行我的‘main.py’配置”,然后再按一次按键“选择并运行我的‘py.test’配置”——但是任何意味着我不会不断地寻找配置列表的东西都会有所帮助。

我尝试录制一个切换配置然后运行的宏,但宏录制器实际上并未记录“更改配置”步骤 - 宏中最终的所有内容都是“运行”。而且似乎没有宏编辑器可以让我手动添加该步骤。

我还知道弹出的“选择配置并运行”列表 (F9),但这仍然需要我读取列表中选择的配置,决定它是否是我想要的配置,然后在列表中向上或向下移动光标在按 Enter 之前。虽然没有那么复杂,但每次做的时候还是会彻底打断我的思路。运行(测试和应用程序)应该比这更简单。

Two actions that I perform on a regular basis are "run my tests" and "run my application". Unfortunately, PyCharm uses the same keystroke (Shift+F10, i.e., "Run") for both, and that keystroke uses my "current" run/debug configuration. I have to do a separate step to change configurations, and that step involves finding and selecting the right option from a longish list -- and it also requires taking the time to think about whether I need to switch configurations.

With as frequently as I run both the tests and the app (I'm still relatively new to Python, so I want to check frequently to make sure I haven't broken anything), this is pretty cumbersome -- especially since my usual pattern is "run the tests, and if they pass, then run the app", so I'm switching configurations all the time.

Is there an easier way to run a given configuration? Ideally I'd like to be able to bind a single keystroke to "select and run my 'main.py' configuration", and another single keystroke to "select and run my 'py.test' configuration" -- but anything that means I'm not constantly hunting through a list of configurations would be helpful.

I've tried recording a macro that switches configurations and then runs, but the macro recorder doesn't actually record the "change configurations" step -- all that ends up in the macro is "run". And there doesn't appear to be a macro editor that would let me manually add that step.

I also know about the pop-up "select configuration and run" list (F9), but that still requires me to read which configuration is selected in the list, decide whether it's the one I want, and cursor up or down in the list before hitting Enter. It's not all that complicated, but it still interrupts my train of thought pretty thoroughly every time I do it. Running -- both the tests and the app -- should be simpler than this.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

你又不是我 2024-11-26 11:47:52

我知道这个问题非常老了,但对于任何有同样问题的人来说..就在这里。

我遇到了同样的问题,因为我在同一个项目上有很多很多脚本,并且我想单独运行一个脚本。

您需要做的是,打开脚本(双击),然后在打开后右键单击任何内容,您将看到“运行[脚本]”和一个绿色的播放按钮。

这是照片

I know this question is super old, but to anybody with the same problem.. here it is.

I had the same problem, because I had lots and lots of scripts on the same project, and I wanted to run a script individually.

What you need to do is, open up the script (by double-clicking), and then once it is open, right-click on anything, and you will see "run [the script]" with a green play button.

here is the photo

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文