eric7/Unittest/Interfaces/PytestExecutor.py

Mon, 16 May 2022 17:22:43 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Mon, 16 May 2022 17:22:43 +0200
branch
unittest
changeset 9065
39405e6eba20
parent 9059
e7fd342f8bfc
permissions
-rw-r--r--

Integrated the new testing widget into the eric IDE (compared to as a standalone app) and implemented the 'Show Source' functionality.

# -*- coding: utf-8 -*-

# Copyright (c) 2022 Detlev Offenbach <detlev@die-offenbachs.de>
#

"""
Module implementing the executor for the 'pytest' framework.
"""

import contextlib
import json
import os

from PyQt6.QtCore import QProcess

from .UTExecutorBase import UTExecutorBase


# TODO: implement 'pytest' support in PytestExecutor
class PytestExecutor(UTExecutorBase):
    """
    Class implementing the executor for the 'pytest' framework.
    """
    module = "pytest"
    name = "pytest"
    
    runner = os.path.join(os.path.dirname(__file__), "PytestRunner.py")
    
    def getVersions(self, interpreter):
        """
        Public method to get the test framework version and version information
        of its installed plugins.
        
        @param interpreter interpreter to be used for the test
        @type str
        @return dictionary containing the framework name and version and the
            list of available plugins with name and version each
        @rtype dict
        """
        proc = QProcess()
        proc.start(interpreter, [PytestExecutor.runner, "versions"])
        if proc.waitForFinished(3000):
            exitCode = proc.exitCode()
            if exitCode == 0:
                outputLines = self.readAllOutput(proc).splitlines()
                for line in outputLines:
                    if line.startswith("{") and line.endswith("}"):
                        with contextlib.suppress(json.JSONDecodeError):
                            return json.loads(line)
        
        return {}

eric ide

mercurial