You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I want to write a 'PyTest' function that checks if a specific call to an R function raises the expected warning(s). For example, the call below should generate warning 'facet_by set to none since no stations are given in data':
I am using the 'rpy2' library to call the R function. The 'rpy2' library does not yet seem to allow warnings/errors generated in the R environment to be read in the Python environment. I created 'rpy2' issue 894. This describes the problem in detail.
I see two possible ways ahead:
Wait to see if the rpy2 issue is resolved.
Use a workaround like writing the R output to file in the R environment, (example here).
I prefer option 1.
Personal notes on possible approaches if/when 'rpy2' issue above is resolved
The Python wrapper would write any R warnings/errors to a stream that is returned to the calling function. Or it could write errors/warnings to a log file. The log file name would be the same as the output file name, except that the file name extension would be ".log".
Example code (Python wrapper function):
from rpy2.rinterface_lib.callbacks import logger as rpy2_logger
file_name_log = os.path.join(path, os.path.splitext(file_name)[0] + ".log")
log_file_handler = logging.FileHandler(file_name_log)
rpy2_logger.addHandler(log_file_handler)
Alternatively, the Python wrapper function could ignore the R warnings, and the 'pytest' function could analyse the warnings directly (see pytest warning documentation here and here).
The text was updated successfully, but these errors were encountered:
I want to write a 'PyTest' function that checks if a specific call to an R function raises the expected warning(s). For example, the call below should generate warning 'facet_by set to none since no stations are given in data':
I am using the 'rpy2' library to call the R function. The 'rpy2' library does not yet seem to allow warnings/errors generated in the R environment to be read in the Python environment. I created 'rpy2' issue 894. This describes the problem in detail.
I see two possible ways ahead:
rpy2
issue is resolved.I prefer option 1.
Personal notes on possible approaches if/when 'rpy2' issue above is resolved
The Python wrapper would write any R warnings/errors to a stream that is returned to the calling function. Or it could write errors/warnings to a log file. The log file name would be the same as the output file name, except that the file name extension would be ".log".
Example code (Python wrapper function):
Example code ('pytest' function):
Alternatively, the Python wrapper function could ignore the R warnings, and the 'pytest' function could analyse the warnings directly (see pytest warning documentation here and here).
The text was updated successfully, but these errors were encountered: