I have a package with many methods that output pandas data frame. I would like to test the examples with pytest and doctest as explained on the pytest doctest integration page.
Pytest requires the output data frame to contain a certain number of columns that might be different than the number of columns provided in the example.
>>> import pandas
>>> df = pandas.DataFrame({"variable_1": range(3)})
>>> for i in range(2, 8): df["variable_"+str(i)] = range(3)
>>> df
variable_1 variable_2 variable_3 variable_4 variable_5 variable_6 variable_7
0 0 0 0 0 0 0 0
1 1 1 1 1 1 1 1
2 2 2 2 2 2 2 2
pytest --doctest-modules returns the following error because it displays 6 columns instead of 7
Differences (unified diff with -expected +actual):
@@ -1,4 +1,6 @@
- variable_1 variable_2 variable_3 variable_4 variable_5 variable_6 variable_7
-0 0 0 0 0 0 0 0
-1 1 1 1 1 1 1 1
-2 2 2 2 2 2 2 2
+ variable_1 variable_2 variable_3 ... variable_5 variable_6 variable_7
+0 0 0 0 ... 0 0 0
+1 1 1 1 ... 1 1 1
+2 2 2 2 ... 2 2 2
+<BLANKLINE>
+[3 rows x 7 columns]
Is there a way to fix the number of column? Does doctest always have a fixed terminal output?