             return
         }
 
-        defer {
+        addTeardownBlock {
             // allow zip files to propagate through object storage, so that
             // they will be deleted when the service deletes the classifier
             // (otherwise they remain and dramatically slow down the tests)
             sleep(15) // wait 15 seconds
 
-            let expectation = self.expectation(description: "Delete the new classifier.")
-
-            visualRecognition.deleteClassifier(classifierID: newClassifierID, failure: failWithError) {
-                expectation.fulfill()
-            }
-            waitForExpectations()
+            let teardownExpectation = self.expectation(description: "Delete the new classifier.")
+
+            self.visualRecognition.deleteClassifier(classifierID: newClassifierID, failure: nil) {
+                teardownExpectation.fulfill()
+            }
+            self.wait(for: [teardownExpectation], timeout: VisualRecognitionTests.timeout)
         }
 
         var trained = false

        let expectation = self.expectation(description: "Retrieve a list of user-trained classifiers.")

        visualRecognition.listClassifiers(verbose: true, failure: failWithError) { classifiers in
            for classifier in classifiers.classifiers {
                if classifier.classifierID == self.classifierID {
                    expectation.fulfill()
                    return
                }
            }
            XCTFail("Could not retrieve the trained classifier.")
        }

            return
        }

        addTeardownBlock {
            // allow zip files to propagate through object storage, so that
            // they will be deleted when the service deletes the classifier
            // (otherwise they remain and dramatically slow down the tests)
            sleep(15) // wait 15 seconds

            let teardownExpectation = self.expectation(description: "Delete the new classifier.")

            self.visualRecognition.deleteClassifier(classifierID: newClassifierID, failure: nil) {
                teardownExpectation.fulfill()
            }
            self.wait(for: [teardownExpectation], timeout: VisualRecognitionTests.timeout)
        }

        var trained = false
