If you are running on a HPC cluster, one common reason for this error is are running test on a node without GPU.
Under the context of HPC, It's a common practice to setup environment on login nodes which are without GPU in most cases. You have to run your test on a node that with GPU and Nvidia drivers.