In Module FileCount.py I have a simple Python Unittest, which tests that the number of files in current directory is greater than zero, so the test should never fail.
import unittest
import pathlib
class Test(unittest.TestCase):
def setUp(self):
pass
def tearDown(self):
pass
def test_file_count(self):
self.assertGreater(
len(list(pathlib.Path().cwd().glob('*'))), 0)
pass
The Python Tool-Class referencing the Unittest is like:
class DemoUnittest(object):
def __init__(self):
"""Define the tool (tool name is the name of the class)."""
self.label = "Demo_Unittest"
self.description = "Execute a Unittest"
self.canRunInBackground = True
def getParameterInfo(self):
"""Define parameter definitions"""
params = None
return params
def isLicensed(self):
"""Set whether tool is licensed to execute."""
return True
def updateParameters(self, parameters):
"""Modify the values and properties of parameters before internal validation is performed. This method is called whenever a parameter has been changed."""
return
def updateMessages(self, parameters):
"""Modify the messages created by internal validation for each tool parameter. This method is called after internal validation."""
return
def execute(self, parameters, messages):
"""The source code of the tool."""
try:
self.result = unittest.TextTestRunner().run(
unittest.TestLoader().loadTestsFromModule(
module = FileCount))
arcpy.AddMessage(self.result)
except Exception as e:
arcpy.AddMessage(str(e))
return True
def postExecute(self, parameters):
arcpy.AddMessage(self.result)
"""This method takes place after outputs are processed and added to the display."""
return
When running the Python Tool in ArcGIS Pro I get the following result:

So from the screen dump above, I conclude the Unittest performed as expected (OK).
But why is ArcGIS Pro telling me erroneously "Failed to execute (DemoUnittest)"?
Thank You for your attention.