get('Magento\Framework\Registry'); $registry->unregister('isSecureArea'); $registry->register('isSecureArea', true); $productRepository = \Magento\TestFramework\Helper\Bootstrap::getObjectManager() ->get('Magento\Catalog\Api\ProductRepositoryInterface'); try { $product = $productRepository->get('bundle-product', false, null, true); $productRepository->delete($product); } catch (\Magento\Framework\Exception\NoSuchEntityException $e) { //Product already removed } $registry->unregister('isSecureArea'); $registry->register('isSecureArea', false);