Repository: django-import-export/django-import-export (language: python)

Issue:
Test needed to cover `collect_failed_row` option
**Describe the bug**

We have a line of code which is not covered by tests:

https://coveralls.io/builds/65434344/source?filename=import_export%2Fresources.py#L945

**Versions (please complete the following information):**
 - Django Import Export: v4 beta
 - Django [e.g. 1.2, 2.0]

**Expected behavior**

We should get back up to 100% coverage.



Discussion / hints:
Hi @matthewhegarty 

So, we need to write a test case to trigger `collect_failed_row` . Am i thinking correctly? 
Yes, that is correct.  We need coverage in the v4 branch for that single line.  You can set breakpoints and run the existing tests to find examples of tests which already cover that section of code.

For example, [this test](https://github.com/django-import-export/django-import-export/blob/0454e8846392f6a4d74a69d492ef41368718bec4/tests/core/tests/test_resources/test_modelresource/test_error_handling.py#L149) will hit that line if you pass `collect_failed_rows=True` to `import_data`.

Do you want to take it on?

Fix patch:
diff --git a/docs/changelog.rst b/docs/changelog.rst
index 34e684d6f..3b8004185 100644
--- a/docs/changelog.rst
+++ b/docs/changelog.rst
@@ -19,6 +19,7 @@ Changelog
 - Added specific check for declared :attr:`~import_export.options.ResourceOptions.import_id_fields` not in dataset
   (#1735)
 - Updated Admin integration documentation to clarify how to save custom form values (#1746)
+- Updated test coverage to include error row when ``collect_failed_rows`` is ``True`` (#1753)
 
 4.0.0-beta.2 (2023-12-09)
 -------------------------


Test patch:
diff --git a/tests/core/tests/test_resources/test_modelresource/test_error_handling.py b/tests/core/tests/test_resources/test_modelresource/test_error_handling.py
index 2f2375167..7bd1f5afd 100644
--- a/tests/core/tests/test_resources/test_modelresource/test_error_handling.py
+++ b/tests/core/tests/test_resources/test_modelresource/test_error_handling.py
@@ -162,3 +162,19 @@ def test_row_result_raise_ValidationError(self):
                     use_transactions=True,
                     raise_errors=True,
                 )
+
+    @ignore_widget_deprecation_warning
+    def test_row_result_raise_ValidationError_collect_failed_rows(self):
+        # 1752
+        resource = ProfileResource()
+        row = ["1"]
+        dataset = tablib.Dataset(row, headers=["id"])
+        with mock.patch(
+            "import_export.resources.Field.save", side_effect=ValidationError("fail!")
+        ):
+            res = resource.import_data(
+                dataset, use_transactions=True, collect_failed_rows=True
+            )
+        self.assertEqual(
+            res.failed_dataset.dict[0], {"id": "1", "Error": "{'__all__': ['fail!']}"}
+        )