# eric7.Testing.TestingWidget

Module implementing a widget to orchestrate unit test execution.

### Global Attributes

None

### Classes

TestingWidget | Class implementing a widget to orchestrate unit test execution.
TestingWidgetModes | Class defining the various modes of the testing widget.
TestingWindow | Main window class for the standalone dialog.

### Functions

clearSavedHistories | Function to clear the saved history lists.

## TestingWidget

Class implementing a widget to orchestrate unit test execution.

### Signals

testFile(str, int, bool)
  emitted to show the source of a test file
testRunStopped()
  emitted after a test run has finished

### Derived from

QWidget, Ui_TestingWidget

### Class Attributes

TestCaseFileRole
TestCaseIdRole
TestCaseLinenoRole
TestCaseNameRole

### Class Methods

None

### Methods

TestingWidget | Constructor
__adjustPendingState | Private method to change the status indicator of all still pending tests to "not run".
__coverageData | Private slot to handle the 'coverageData' signal of the executor.
__determineInterpreter | Private method to determine the interpreter to be used.
__discoverTests | Private slot to discover tests but don't execute them.
__findDiscoveryItem | Private method to find an item given the module path.
__insertDiscovery | Private slot to insert the discovery start directory into the discoveryPicker object.
__insertHistory | Private slot to insert an item into a history object.
__insertTestFile | Private slot to insert a test file name into the testsuitePicker object.
__insertTestName | Private slot to insert a test name into the testComboBox object.
__loadRecent | Private method to load the most recently used lists.
__openEditor | Private method to open an editor window for the given file.
__populateTestFrameworkComboBox | Private method to (re-)populate the test framework selector.
__populateVenvComboBox | Private method to (re-)populate the virtual environments selector.
__processTestResult | Private slot to handle the receipt of a test result object.
__projectClosed | Private slot to handle a project being closed.
__projectOpened | Private slot to handle a project being opened.
__resetResults | Private slot to reset the test results tab and data.
__saveRecent | Private method to save the most recently used lists.
__selectedTestCases | Private method to assemble the list of selected test cases and suites.
__setDiscoverMode | Private slot to switch the widget to test discovery mode.
__setIdleMode | Private slot to switch the widget to idle mode.
__setRunningMode | Private slot to switch the widget to running mode.
__setStatusLabel | Private slot to set the status label to the text sent by the model.
__setStoppedMode | Private slot to switch the widget to stopped mode.
__showCoverageDialog | Private slot to show a code coverage dialog for the most recent test run.
__showLogOutput | Private slot to show the output of the most recent test run.
__showSource | Private slot to show the source of a traceback in an editor.
__stopTests | Private slot to stop the current test run.
__testDiscoveryAboutToBeStarted | Private slot to handle the 'testDiscoveryAboutToBeStarted' signal of the executor.
__testDiscoveryError | Private slot handling the 'collectError' signal of the executor.
__testDiscoveryProcessFinished | Private slot to handle the 'testFinished' signal of the executor in discovery mode.
__testProcessFinished | Private slot to handle the 'testFinished' signal of the executor.
__testRunAboutToBeStarted | Private slot to handle the 'testRunAboutToBeStarted' signal of the executor.
__testRunFinished | Private slot to handle the 'testRunFinished' signal of the executor.
__testStarted | Private slot handling the 'startTest' signal of the executor.
__testsCollectError | Private slot handling the 'collectError' signal of the executor.
__testsCollected | Private slot handling the 'collected' signal of the executor.
__testsDiscovered | Private slot handling the 'collected' signal of the executor in discovery mode.
__testsStopped | Private slot to handle the 'stop' signal of the executor.
__updateButtonBoxButtons | Private slot to update the state of the buttons of the button box.
__updateCoverage | Private slot to update the state of the coverage checkbox depending on the selected framework's capabilities.
__updateMarkerSupport | Private slot to update the state of the marker related widgets depending on the selected framework's capabilities.
__updatePatternSupport | Private slot to update the state of the test name pattern line edit depending on the selected framework's capabilities.
__updateProgress | Private slot to update the progress indicators.
__updateStatusFilterComboBox | Private method to update the status filter dialog box.
clearRecent | Public slot to clear the recently used lists.
closeEvent | Protected method to handle the close event.
getFailedTests | Public method to get the list of failed tests (if any).
getResultsModel | Public method to get a reference to the model containing the test result data.
hasFailedTests | Public method to check for failed tests.
on_buttonBox_clicked | Private slot called by a button of the button box clicked.
on_discoverCheckBox_toggled | Private slot handling state changes of the 'discover' checkbox.
on_discoveryList_customContextMenuRequested | Private slot to show the context menu of the dicovery list.
on_discoveryList_itemActivated | Private slot handling the user activating an item.
on_discoveryList_itemChanged | Private slot handling the user checking or unchecking an item.
on_discoveryPicker_editTextChanged | Private slot to handle a change of the discovery start directory.
on_frameworkComboBox_currentIndexChanged | Private slot handling the selection of a test framework.
on_showMarkersButton_clicked | Private slot to show a window containing the list of defined markers.
on_statusFilterComboBox_currentTextChanged | Private slot handling the selection of a status for items to be shown.
on_testsuitePicker_aboutToShowPathPickerDialog | Private slot called before the test file selection dialog is shown.
on_venvComboBox_currentIndexChanged | Private slot handling the selection of a virtual environment.
on_versionsButton_clicked | Private slot to show the versions of available plugins.
setTestFile | Public slot to set the given test file as the current one.
startTests | Public slot to start the test run.

### Static Methods

None

#### TestingWidget (Constructor)

TestingWidget(testfile=None, parent=None)

Constructor

testfile (str)
  file name of the test to load
parent (QWidget (optional))
  reference to the parent widget (defaults to None)

#### TestingWidget.__adjustPendingState

__adjustPendingState()

Private method to change the status indicator of all still pending tests to "not run".

#### TestingWidget.__coverageData

__coverageData(coverageFile)

Private slot to handle the 'coverageData' signal of the executor.

coverageFile (str)
  file containing the coverage data

#### TestingWidget.__determineInterpreter

__determineInterpreter(venvName)

Private method to determine the interpreter to be used.

venvName (str)
  name of the virtual environment

Return:
  path of the interpreter executable

Return Type:
  str

#### TestingWidget.__discoverTests

__discoverTests()

Private slot to discover tests but don't execute them.

#### TestingWidget.__findDiscoveryItem

__findDiscoveryItem(modulePath)

Private method to find an item given the module path.

modulePath (str)
  path of the module in dotted notation

Return:
  reference to the item or None

Return Type:
  QTreeWidgetItem or None

#### TestingWidget.__insertDiscovery

__insertDiscovery(start)

Private slot to insert the discovery start directory into the discoveryPicker object.

start (str)
  start directory name to be inserted

#### TestingWidget.__insertHistory

__insertHistory(widget, history, item)

Private slot to insert an item into a history object.

widget (QComboBox or EricComboPathPicker)
  reference to the widget
history (list of str)
  array containing the history
item (str)
  item to be inserted

#### TestingWidget.__insertTestFile

__insertTestFile(prog)

Private slot to insert a test file name into the testsuitePicker object.

prog (str)
  test file name to be inserted

#### TestingWidget.__insertTestName

__insertTestName(testName)

Private slot to insert a test name into the testComboBox object.

testName (str)
  name of the test to be inserted

#### TestingWidget.__loadRecent

__loadRecent()

Private method to load the most recently used lists.

#### TestingWidget.__openEditor

__openEditor(filename, linenumber=1)

Private method to open an editor window for the given file.

Note: This method opens an editor window when the testing dialog is called as a standalone application.

filename (str)
  path of the file to be opened
linenumber (int (optional))
  line number to place the cursor at (defaults to 1)

#### TestingWidget.__populateTestFrameworkComboBox

__populateTestFrameworkComboBox()

Private method to (re-)populate the test framework selector.

#### TestingWidget.__populateVenvComboBox

__populateVenvComboBox()

Private method to (re-)populate the virtual environments selector.

#### TestingWidget.__processTestResult

__processTestResult(result)

Private slot to handle the receipt of a test result object.

result (TestResult)
  test result object

#### TestingWidget.__projectClosed

__projectClosed()

Private slot to handle a project being closed.

#### TestingWidget.__projectOpened

__projectOpened()

Private slot to handle a project being opened.

#### TestingWidget.__resetResults

__resetResults()

Private slot to reset the test results tab and data.

#### TestingWidget.__saveRecent

__saveRecent()

Private method to save the most recently used lists.

#### TestingWidget.__selectedTestCases

__selectedTestCases(parent=None)

Private method to assemble the list of selected test cases and suites.

parent (QTreeWidgetItem)
  reference to the parent item

Return:
  list of selected test cases

Return Type:
  list of str

#### TestingWidget.__setDiscoverMode

__setDiscoverMode()

Private slot to switch the widget to test discovery mode.

#### TestingWidget.__setIdleMode

__setIdleMode()

Private slot to switch the widget to idle mode.

#### TestingWidget.__setRunningMode

__setRunningMode()

Private slot to switch the widget to running mode.

#### TestingWidget.__setStatusLabel

__setStatusLabel(statusText)

Private slot to set the status label to the text sent by the model.

statusText (str)
  text to be shown

#### TestingWidget.__setStoppedMode

__setStoppedMode()

Private slot to switch the widget to stopped mode.

#### TestingWidget.__showCoverageDialog

__showCoverageDialog()

Private slot to show a code coverage dialog for the most recent test run.

#### TestingWidget.__showLogOutput

__showLogOutput()

Private slot to show the output of the most recent test run.

#### TestingWidget.__showSource

__showSource(filename, lineno)

Private slot to show the source of a traceback in an editor.

filename (str)
  file name of the file to be shown
lineno (int)
  line number to go to in the file

#### TestingWidget.__stopTests

__stopTests()

Private slot to stop the current test run.

#### TestingWidget.__testDiscoveryAboutToBeStarted

__testDiscoveryAboutToBeStarted()

Private slot to handle the 'testDiscoveryAboutToBeStarted' signal of the executor.

#### TestingWidget.__testDiscoveryError

__testDiscoveryError(errors)

Private slot handling the 'collectError' signal of the executor.

errors (list of tuple of (str, str))
  list of tuples containing the test name and a description of the error

#### TestingWidget.__testDiscoveryProcessFinished

__testDiscoveryProcessFinished(_results, output)

Private slot to handle the 'testFinished' signal of the executor in discovery mode.

_results (list of TestResult)
  list of test result objects (if not sent via the 'testResult' signal) (unused)
output (str)
  string containing the test process output (if any)

#### TestingWidget.__testProcessFinished

__testProcessFinished(_results, output)

Private slot to handle the 'testFinished' signal of the executor.

_results (list of TestResult)
  list of test result objects (if not sent via the 'testResult' signal) (unused)
output (str)
  string containing the test process output (if any)

#### TestingWidget.__testRunAboutToBeStarted

__testRunAboutToBeStarted()

Private slot to handle the 'testRunAboutToBeStarted' signal of the executor.

#### TestingWidget.__testRunFinished

__testRunFinished(noTests, duration)

Private slot to handle the 'testRunFinished' signal of the executor.

noTests (int)
  number of tests run by the executor
duration (float)
  time needed in seconds to run the tests

#### TestingWidget.__testStarted

__testStarted(test)

Private slot handling the 'startTest' signal of the executor.

test (tuple of (str, str, str))
  tuple containing the id, name and short description of the tests about to be run

#### TestingWidget.__testsCollectError

__testsCollectError(errors)

Private slot handling the 'collectError' signal of the executor.

errors (list of tuple of (str, str))
  list of tuples containing the test name and a description of the error

#### TestingWidget.__testsCollected

__testsCollected(testNames)

Private slot handling the 'collected' signal of the executor.

testNames (list of tuple of (str, str, str, str, int, list))
  list of tuples containing the test id, the test name a description, the file name, the line number and the test path as a list of collected tests

#### TestingWidget.__testsDiscovered

__testsDiscovered(testNames)

Private slot handling the 'collected' signal of the executor in discovery mode.

testNames (list of tuple of (str, str, str, str, int, list))
  list of tuples containing the test id, the test name a description, the file name, the line number and the test path as a list of collected tests

#### TestingWidget.__testsStopped

__testsStopped()

Private slot to handle the 'stop' signal of the executor.

#### TestingWidget.__updateButtonBoxButtons

__updateButtonBoxButtons()

Private slot to update the state of the buttons of the button box.

#### TestingWidget.__updateCoverage

__updateCoverage()

Private slot to update the state of the coverage checkbox depending on the selected framework's capabilities.

#### TestingWidget.__updateMarkerSupport

__updateMarkerSupport()

Private slot to update the state of the marker related widgets depending on the selected framework's capabilities.

#### TestingWidget.__updatePatternSupport

__updatePatternSupport()

Private slot to update the state of the test name pattern line edit depending on the selected framework's capabilities.

#### TestingWidget.__updateProgress

__updateProgress()

Private slot to update the progress indicators.

#### TestingWidget.__updateStatusFilterComboBox

__updateStatusFilterComboBox()

Private method to update the status filter dialog box.

#### TestingWidget.clearRecent

clearRecent()

Public slot to clear the recently used lists.

#### TestingWidget.closeEvent

closeEvent(event)

Protected method to handle the close event.

event (QCloseEvent)
  close event

#### TestingWidget.getFailedTests

getFailedTests()

Public method to get the list of failed tests (if any).

Return:
  list of IDs of failed tests

Return Type:
  list of str

#### TestingWidget.getResultsModel

getResultsModel()

Public method to get a reference to the model containing the test result data.

Return:
  reference to the test results model

Return Type:
  TestResultsModel

#### TestingWidget.hasFailedTests

hasFailedTests()

Public method to check for failed tests.

Return:
  flag indicating the existence of failed tests

Return Type:
  bool

#### TestingWidget.on_buttonBox_clicked

on_buttonBox_clicked(button)

Private slot called by a button of the button box clicked.

button (QAbstractButton)
  button that was clicked

#### TestingWidget.on_discoverCheckBox_toggled

on_discoverCheckBox_toggled(_checked)

Private slot handling state changes of the 'discover' checkbox.

_checked (bool)
  state of the checkbox (unused)

#### TestingWidget.on_discoveryList_customContextMenuRequested

on_discoveryList_customContextMenuRequested(pos)

Private slot to show the context menu of the dicovery list.

pos (QPoint)
  the position of the mouse pointer

#### TestingWidget.on_discoveryList_itemActivated

on_discoveryList_itemActivated(item, column)

Private slot handling the user activating an item.

item (QTreeWidgetItem)
  reference to the item
column (int)
  column of the double click

#### TestingWidget.on_discoveryList_itemChanged

on_discoveryList_itemChanged(item, column)

Private slot handling the user checking or unchecking an item.

item (QTreeWidgetItem)
  reference to the item
column (int)
  changed column

#### TestingWidget.on_discoveryPicker_editTextChanged

on_discoveryPicker_editTextChanged(txt)

Private slot to handle a change of the discovery start directory.

txt (str)
  new discovery start directory

#### TestingWidget.on_frameworkComboBox_currentIndexChanged

on_frameworkComboBox_currentIndexChanged(index)

Private slot handling the selection of a test framework.

index (int)
  index of the selected framework

#### TestingWidget.on_showMarkersButton_clicked

on_showMarkersButton_clicked()

Private slot to show a window containing the list of defined markers.

#### TestingWidget.on_statusFilterComboBox_currentTextChanged

on_statusFilterComboBox_currentTextChanged(status)

Private slot handling the selection of a status for items to be shown.

status (str)
  selected status

#### TestingWidget.on_testsuitePicker_aboutToShowPathPickerDialog

on_testsuitePicker_aboutToShowPathPickerDialog()

Private slot called before the test file selection dialog is shown.

#### TestingWidget.on_venvComboBox_currentIndexChanged

on_venvComboBox_currentIndexChanged(index)

Private slot handling the selection of a virtual environment.

index (int)
  index of the selected environment

#### TestingWidget.on_versionsButton_clicked

on_versionsButton_clicked()

Private slot to show the versions of available plugins.

#### TestingWidget.setTestFile

setTestFile(testFile, forProject=False)

Public slot to set the given test file as the current one.

testFile (str)
  path of the test file
forProject (bool (optional))
  flag indicating that this call is for a project (defaults to False)

#### TestingWidget.startTests

startTests(failedOnly=False, debug=False)

Public slot to start the test run.

failedOnly (bool (optional))
  flag indicating to run only failed tests (defaults to False)
debug (bool (optional))
  flag indicating to start the test run with debugger support (defaults to False)

Up

## TestingWidgetModes

Class defining the various modes of the testing widget.

### Derived from

enum.Enum

### Class Attributes

DISCOVERY
IDLE
RUNNING
STOPPED

### Class Methods

None

### Methods

None

### Static Methods

None

Up

## TestingWindow

Main window class for the standalone dialog.

### Derived from

EricMainWindow

### Class Attributes

None

### Class Methods

None

### Methods

TestingWindow | Constructor
eventFilter | Public method to filter events.

### Static Methods

None

#### TestingWindow (Constructor)

TestingWindow(testfile=None, parent=None)

Constructor

testfile (str)
  file name of the test script to open
parent (QWidget)
  reference to the parent widget

#### TestingWindow.eventFilter

eventFilter(_obj, event)

Public method to filter events.

_obj (QObject)
  reference to the object the event is meant for (unused)
event (QEvent)
  reference to the event object

Return:
  flag indicating, whether the event was handled

Return Type:
  bool

Up

## clearSavedHistories

clearSavedHistories(self)

Function to clear the saved history lists.

Up