By Alan Baldwin

AUSTIN, Texas, Oct 21 (Reuters) - Formula One teams have agreed a compromise to switch next year's first in-season test from Barcelona to Bahrain following a failed attempt to move winter testing to the warmer climes of the Middle East.

Red Bull principal Christian Horner told reporters that all the teams had met the sport's commercial supremo Bernie Ecclestone at the U.S. Grand Prix on Friday to discuss the situation.

Testing outside of Europe, according to the sporting regulations, requires the unanimous agreement of all the teams and Horner said a vote conducted earlier in the week by the governing FIA did not achieve that.

"It's agreed that we will test in Barcelona pre-season," he said. "And that in order to hopefully find a compromise for assisting Pirelli, after the Bahrain race the first of the in-season tests is planned to be in Bahrain.

"Hopefully commonsense has prevailed."

Bahrain is scheduled to be the third round of the 2017 season, at the Sakhir circuit on April 16, with Spain the fifth race on May 14.

The championship is set to start in Australia on March 26 and temperatures in Barcelona in February and early March, when the two four-day pre-season tests are scheduled, can often be cold and damp.

Testing is all the more important next season with new regulations that will see cars lapping much faster on wider tyres.

Pirelli say they need to test the 2017 tyres in hot conditions and have expressed concern about what might happen otherwise.

Holding a pre-season test in Bahrain is far more expensive than doing so in Europe, however, and there is also the risk of sandstorms.

While world champions Mercedes were keen on going to the Middle East, Williams and others were opposed to leaving Europe on cost grounds.

(Editing by Tony Jimenez) ((alan.baldwin@thomsonreuters.com; +442075427933; Reuters Messaging: Reuters Messaging: alan.baldwin.reuters.com@thomsonreuters.net))