Skip to content

squape.report

section

section(title, description='')

Allows using Squish's sections as context managers and function decorators https://doc.qt.io/squish/squish-api.html#test-startsection-function

description (str): Optional additional description of the section

Examples:

with section("Add new person"):
    squish.type(squish.waitForObject(names.forename_edit), "Bob")
    squish.mouseClick(squish.waitForObject(names.ok_button))
Source code in squape/report.py
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
def __init__(self, title, description=""):
    """
    Args:
        title (str): Section title
        description (str): Optional additional description of the section

    Examples:
        ```python
        with section("Add new person"):
            squish.type(squish.waitForObject(names.forename_edit), "Bob")
            squish.mouseClick(squish.waitForObject(names.ok_button))
        ```
    """
    self.title = title
    self.description = description

debug

debug(msg, details='')

Adds a DEBUG-level log entry with the given message and details to a test report.

This function adds a log message to Squish's test report at the DEBUG log level, which allows for detailed debugging information to be recorded. The log message will include the given message and details provided as arguments. The message will be prefixed with the string 'DEBUG: ' to indicate its log level.

The log message will only be visible if the LOGLEVEL is set to DEBUG. Otherwise, it will be ignored and not included in the test report.

Parameters:

Name Type Description Default
msg str

The message to include in the log entry.

required
details str

Optional additional details to include in the log entry.

''

Returns:

Type Description
None

None

Source code in squape/report.py
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
def debug(msg: str, details: str = "") -> None:
    """Adds a DEBUG-level log entry with the given message and details to a test report.

    This function adds a log message to Squish's test report at the DEBUG log level,
    which allows for detailed debugging information to be recorded.
    The log message will include the given message and details provided as arguments.
    The message will be prefixed with the string 'DEBUG: ' to indicate its log level.

    The log message will only be visible if the LOGLEVEL is set to DEBUG.
    Otherwise, it will be ignored and not included in the test report.

    Args:
        msg (str): The message to include in the log entry.
        details (str): Optional additional details to include in the log entry.

    Returns:
        None
    """
    if __is_level_enabled(LogLevel.DEBUG):
        test.fixateResultContext(1)
        try:
            _test_log(f"[DEBUG] {msg}", details)
        finally:
            test.restoreResultContext()

enable_loglevel_in_test_module

enable_loglevel_in_test_module()

Adds support for log levels to the Squish 'test' module.

Warning

This function uses monkey pathching https://en.wikipedia.org/wiki/Monkey_patch

This function overwrites some of the existing functions in the 'test' module to support logging at different log levels. Furthermore, it enhances the functionality of the 'test' module by adding a new test.debug(...) function.

By default, the 'test' module does not support LOGLEVEL at all. However, this function adds support for setting the log level to a higher or lower level, depending on the needs of the developer.

After calling this function, the following 'test' module's functions will support LOGLEVEL report setting:

- test.debug(...)
- test.log(...)
- test.warning(...)
- test.fail(...)
- test.fatal(...)

Returns:

Type Description
None

None

Source code in squape/report.py
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
def enable_loglevel_in_test_module() -> None:
    """Adds support for log levels to the Squish 'test' module.

    !!! warning
        This function uses monkey pathching
        https://en.wikipedia.org/wiki/Monkey_patch

    This function overwrites some of the existing functions in the 'test' module
    to support logging at different log levels.
    Furthermore, it enhances the functionality of the 'test' module by adding
    a new test.debug(...) function.

    By default, the 'test' module does not support LOGLEVEL at all.
    However, this function adds support for setting the log level to a higher
    or lower level, depending on the needs of the developer.

    After calling this function, the following 'test' module's functions will support
    LOGLEVEL report setting:

        - test.debug(...)
        - test.log(...)
        - test.warning(...)
        - test.fail(...)
        - test.fatal(...)

    Returns:
        None
    """
    test.debug = debug
    test.log = log
    test.warning = warning
    test.fail = fail
    test.fatal = fatal

fail

fail(msg, details='')

Adds a fail entry with the given message and details to a test report.

This function adds a fail message to Squish's test report at the FAIL log level or lower, depending on the current log level setting. The fail message will include the given message and details provided as arguments.

The fail message will only be visible if the LOGLEVEL is set to FAIL or lower. Otherwise, it will be ignored and not included in the test report.

Parameters:

Name Type Description Default
msg str

The message to include in the fail entry.

required
details str

Optional additional details to include in the fail entry.

''

Returns:

Type Description
None

None

Source code in squape/report.py
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
def fail(msg: str, details: str = "") -> None:
    """Adds a fail entry with the given message and details to a test report.

    This function adds a fail message to Squish's test report at the FAIL log level
    or lower, depending on the current log level setting.
    The fail message will include the given message and details provided as arguments.

    The fail message will only be visible if the LOGLEVEL is set to FAIL or lower.
    Otherwise, it will be ignored and not included in the test report.

    Args:
        msg (str): The message to include in the fail entry.
        details (str): Optional additional details to include in the fail entry.

    Returns:
        None
    """
    if __is_level_enabled(LogLevel.FAIL):
        test.fixateResultContext(1)
        try:
            _test_fail(msg, details)
        finally:
            test.restoreResultContext()

fatal

fatal(msg, details='')

Adds a fatal entry with the given message and details to a test report, then aborts the test case execution.

This function adds a fatal message to Squish's test report at the FATAL log level or lower, depending on the current log level setting. The fatal message will include the given message and details provided as arguments.

The fatal message will only be visible if the LOGLEVEL is set to FATAL or lower. Otherwise, it will be ignored and not included in the test report.

After adding the fatal message, the function aborts the test case execution.

Parameters:

Name Type Description Default
msg str

The message to include in the fatal entry.

required
details str

Optional additional details to include in the fatal entry.

''

Returns:

Type Description
None

None

Source code in squape/report.py
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
def fatal(msg: str, details: str = "") -> None:
    """Adds a fatal entry with the given message and details to a test report,
    then aborts the test case execution.

    This function adds a fatal message to Squish's test report at the FATAL log level
    or lower, depending on the current log level setting.
    The fatal message will include the given message and details provided as arguments.

    The fatal message will only be visible if the LOGLEVEL is set to FATAL or lower.
    Otherwise, it will be ignored and not included in the test report.

    After adding the fatal message, the function aborts the test case execution.

    Args:
        msg (str): The message to include in the fatal entry.
        details (str): Optional additional details to include in the fatal entry.

    Returns:
        None
    """
    if __is_level_enabled(LogLevel.FATAL):
        test.fixateResultContext(1)
        try:
            squish.testSettings.throwOnFailure = True
            _test_fatal(msg, details)
        finally:
            test.restoreResultContext()

log

log(msg, details='')

Adds a log entry with the given message and details to a test report.

This function adds a log message to Squish's test report at the LOG log level or lower, depending on the current log level setting. The log message will include the given message and details provided as arguments.

The log message will only be visible if the LOGLEVEL is set to LOG or lower. Otherwise, it will be ignored and not included in the test report.

Parameters:

Name Type Description Default
msg str

The message to include in the log entry.

required
details str

Optional additional details to include in the log entry.

''

Returns:

Type Description
None

None

Source code in squape/report.py
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
def log(msg: str, details: str = "") -> None:
    """Adds a log entry with the given message and details to a test report.

    This function adds a log message to Squish's test report at the LOG log level
    or lower, depending on the current log level setting.
    The log message will include the given message and details provided as arguments.

    The log message will only be visible if the LOGLEVEL is set to LOG or lower.
    Otherwise, it will be ignored and not included in the test report.

    Args:
        msg (str): The message to include in the log entry.
        details (str): Optional additional details to include in the log entry.

    Returns:
        None
    """
    if __is_level_enabled(LogLevel.LOG):
        test.fixateResultContext(1)
        try:
            _test_log(msg, details)
        finally:
            test.restoreResultContext()

set_level

set_level(level)

Sets the Squish logging level, Level must be an int or a str.

Parameters:

Name Type Description Default
level int | str

log level to set

required

Examples:

>>> set_level(report.LogLevel.WARNING)
>>> set_level("FAIL")
Source code in squape/report.py
51
52
53
54
55
56
57
58
59
60
61
62
def set_level(level) -> None:
    """Sets the Squish logging level, Level must be an int or a str.

    Args:
        level (int|str): log level to set

    Examples:
       >>> set_level(report.LogLevel.WARNING)
       >>> set_level("FAIL")
    """
    global LOGLEVEL
    LOGLEVEL = __translate_Level(level)

warning

warning(msg, details='')

Adds a warning entry with the given message and details to a test report.

This function adds a warning message to Squish's test report at the WARNING log level or lower, depending on the current log level setting. The warning message will include the given message and details provided as arguments.

The warning message will only be visible if the LOGLEVEL is set to WARNING or lower. Otherwise, it will be ignored and not included in the test report.

Parameters:

Name Type Description Default
msg str

The message to include in the warning entry.

required
details str

Optional additional details to include in the warning entry.

''

Returns:

Type Description
None

None

Source code in squape/report.py
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
def warning(msg: str, details: str = "") -> None:
    """Adds a warning entry with the given message and details to a test report.

    This function adds a warning message to Squish's test report at the WARNING
    log level or lower, depending on the current log level setting.
    The warning message will include the given message and details provided
    as arguments.

    The warning message will only be visible if the LOGLEVEL is set to WARNING or lower.
    Otherwise, it will be ignored and not included in the test report.

    Args:
        msg (str): The message to include in the warning entry.
        details (str): Optional additional details to include in the warning entry.

    Returns:
        None
    """
    if __is_level_enabled(LogLevel.WARNING):
        test.fixateResultContext(1)
        try:
            _test_warning(msg, details)
        finally:
            test.restoreResultContext()