pytest-regressions
pytest-regressions copied to clipboard
Pytest data regression does not recognize float64 as valid object
Got this error when using a data regression on top os a numpy created array of zeros, that creates the array as float64
by default
Can you please provide a code sample that reproduces the error? Or, if not, the stacktrace with the full error message.
Thanks!
Sure
def test_regression(data_regression):
from numpy import float64
float_64_numpy_object = float64(10)
> data_regression.check(float_64_numpy_object)
test_create_scas_calc_dict.py:122:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
/home/gghiguchi/Work/miniconda/envs/rfdap/lib/python3.6/site-packages/pytest_regressions/data_regression.py:55: in dump
encoding="utf-8",
/home/gghiguchi/Work/miniconda/envs/rfdap/lib/python3.6/site-packages/yaml/__init__.py:278: in dump_all
dumper.represent(data)
/home/gghiguchi/Work/miniconda/envs/rfdap/lib/python3.6/site-packages/yaml/representer.py:27: in represent
node = self.represent_data(data)
/home/gghiguchi/Work/miniconda/envs/rfdap/lib/python3.6/site-packages/yaml/representer.py:58: in represent_data
node = self.yaml_representers[None](self, data)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pytest_regressions.data_regression.RegressionYamlDumper object at 0x7f85fe360b38>, data = 10.0
def represent_undefined(self, data):
> raise RepresenterError("cannot represent an object", data)
E yaml.representer.RepresenterError: ('cannot represent an object', 10.0)
/home/gghiguchi/Work/miniconda/envs/rfdap/lib/python3.6/site-packages/yaml/representer.py:231: RepresenterError
Perhaps this can be solved by using the new NDArraysRegressionFixture
? @tovrstra What do you think?
That would indeed be a solution. The code was recently merged in the master branch (#72) and there is still some API discussion (#73). I believe both num_regressions
and ndarrays_regression
should work. Just keep in mind that these expect a dictionionary with strings as keys and arrays as values. If you plan to use other shapes than 1D arrays, ndarrays_regression
would be the best fit.