从上下文菜单中为单个函数运行py.test

时间:2017-04-28 19:38:17

标签: pycharm pytest

在PyCharm(2017.1)中使用Unittest框架我可以右键单击测试用例中的函数并选择Run Unittest for ...

enter image description here

对于我使用py.test的其他项目,上下文菜单中的此条目不再存在。

是否有可能与py.test实现相同而不必为每个测试用例设置专用的运行配置?

2 个答案:

答案 0 :(得分:0)

我有这个,并使缓存失效或重启PycCharm什么也没做。在文件顶部创建了一个新函数:

Sub ExtractFirstUnreadEmailDetails()
    Dim oOlAp As Object, oOlns As Object, oOlInb As Object
    Dim oOlItm As Object
    Dim objAtt As Outlook.Attachment
     'On Error Resume Next
    '~~> Outlook Variables for email

    Dim eSender As String, dtRecvd As String, dtSent As String
    Dim sSubj As String, sMsg As String
    Dim AttchType As String

    '~~> Get Outlook instance
    Set oOlAp = GetObject(, "Outlook.application")
    Set oOlns = oOlAp.GetNamespace("MAPI")
    Set oOlInb = oOlns.GetDefaultFolder(olFolderInbox)

    '~~> Check if there are any actual unread emails 'apurv
    'If oOlInb.Items.Restrict("[UnRead] = True").Count = 0 Then 'apurv
      '  MsgBox "NO Unread Email In Inbox" 'apurv
       ' Exit Sub 'apurv
   ' End If 'apurv

    '~~> Store the relevant info in the variables
    'For Each oOlItm In oOlInb.Items.Restrict("[UnRead] = True")
            For Each oOlItm In oOlInb.Items
                        eSender = oOlItm.SenderEmailAddress
                        dtRecvd = oOlItm.ReceivedTime
                        dtSent = oOlItm.CreationTime
                        sSubj = oOlItm.Subject
                        sMsg = oOlItm.Body
                        ToAddress = oOlItm.To

                    i = ThisWorkbook.ActiveSheet.Cells(Rows.Count, 2).End(xlUp).Row

                         Range("c" & (i + 1)).Value = eSender
                         Range("B" & (i + 1)).Value = dtRecvd
                         'range("c"&(i+1)).Value=dtSent
                         Range("E" & (i + 1)).Value = sSubj
                         Range("F" & (i + 1)).Value = sMsg
                         Range("D" & (i + 1)).Value = ToAddress

                                If oOlItm.Attachments.Count <> 0 Then
                                         temp = ""
                                         For Each oOlAtch In oOlItm.Attachments
                                           temp = temp & "//" & oOlAtch.Filename
                                         Next
                                         Range("G" & (i + 1)).Value = temp
                                End If

                                If oOlItm.Attachments.Count <> 0 Then
                                         temp = ""
                                         For Each oOlAtch In oOlItm.Attachments
                                         If InStr(1, UCase(oOlAtch.Filename), "PDF", vbTextCompare) > 1 Then
                                         oOlAtch.SaveAsFile "D:\Users\apawar\Desktop\Attachments\" & oOlAtch.Filename
                                         Shell "Explorer.exe /e,D:\Users\apawar\Desktop\Attachments\" & oOlAtch.Filename, vbNormalFocus
                                         'NEED HELP HERE......Need to copy all data from pdf doc from 1st page
                                         End If
                                         Next
                                         Range("G" & (i + 1)).Value = temp
                                End If
            Next



MsgBox ("Down loaded successufully")
End Sub

然后PyCharm(2017.2.3)意识到文件是测试,并允许我在上下文菜单中对我的测试类及其test_ *方法运行py.test。

这是一个不整洁的解决方案,但它可能有所帮助。

如果删除虚拟测试功能,该文件只获得Run的选项,而不是py.test。

我的一些Python文件被识别为测试,有些则没有。事情并不明显。

令人讨厌的是,没有用于默认单元测试运行器的键盘快捷键,这与运行不同。两者都是Ctrl + shift + R。

答案 1 :(得分:0)

最近pycharm更新中修复的问题。 我现在使用2017.2.3,它的行为与预期一致。