I noticed that the apex test is passing in Dev Console(unchecked "Always Run Asynchronously") but not via Setup -> Apex Test Execution or through a Validation from a deployment.
As per the developer guide,
All Apex tests that are started from the Salesforce user interface (including the Developer Console) run asynchronously and in parallel.
When code is run asynchronously then no session is available because execution is scheduled when resources are available.
Just think of batch jobs or @future calls. At that point of time, the session of the user who started the job may or may not be available. And that's the reason the method throws exception and this is Working As Designed behavior.
You either need to skip using this method being invoked or use an appropriate workaround to skip this method in async calls.
In similar issues in the past, users have optimized code by adding additional IF logic as if(UserInfo.getSessionId() != Null && !Test.isRunningTest())
And also logic, to check if you're in an asynchronous context or not !System.isQueueable()