PyCharm Plugin: Adding action to EditorPopupMenu.Run to run individual pytest with custom configuration

Answered

I'm new to plugin development I'm trying to create a Pycharm plugin to add an option to the EditorPopupMenu which will only show up if a pytest function is right clicked. I'm aiming for the action to run the individual pytest function which was clicked and be able to do it with a custom configuration to run the tests with a custom built framework tool. 

I know adding an option to the EditorPopupMenu can be done with this:

<action id="HelloWorld" class="actions.HelloWorldAction" text="Hello World">
      <add-to-group group-id="EditorPopupMenu.Run" anchor="first"></add-to-group>
</action>

But I'm having trouble finding documentation that helps with the rest of what I need to do which is:
1. Determine if what was right clicked was a function which follows the naming convention of pytest (test_func)
2. Run that test function with a custom configuration

1
2 comments

Hi,

  1. You should override the AnAction.update() method and enable and show it when the function following the naming convention.  See: https://plugins.jetbrains.com/docs/intellij/basic-action-system.html#overriding-the-anactionupdate-method
    To get the element clicked in the editor, you can use anActionEvent.getData(CommonDataKeys.PSI_ELEMENT)
  2. See https://plugins.jetbrains.com/docs/intellij/run-configurations.html#starting-a-run-configuration-programmatically
1

Thanks for the response. I was actually able to achieve the functionality I was looking for a couple days after my initial question. Just for future reference in case anyone else stumbles upon this thread looking for help, these links were very helpful to me:

 Intellij SDK Code examples: https://github.com/JetBrains/intellij-sdk-code-samples
Pycharm specific Intellij SDK docs: https://plugins.jetbrains.com/docs/intellij/pycharm.html 
Intellij Source Code https://github.com/JetBrains/intellij-community
 

As well as looking up open source plugin source codes with related functionality.

 

0

Please sign in to leave a comment.