Former President Barack Obama told Democrats to avoid “purity tests during elections,” and celebrated the diversity and ambitions of all the Democratic candidates.

“We will not win just by increasing the turnout of the people who already agree with us completely on everything,” Obama said. “Which is why I am always suspicious of purity tests during elections. Because, you know what, the country is complicated.”

His comments came during a question-and-answer session with Democratic National Committee Chairman Tom Perez in Los Altos Hills, California. The fundraiser reportedly raised more than $3 million for the Democratic National Committee.

Obama has remained on the sidelines of the presidential election so far, and has chosen not to endorse a candidate yet. (Although his former Vice President asked him to not endorse him).

The Democratic primary is very crowded and currently holds 17 candidates, five of whom are female, one gay man, and nearly a third are people of color.

“We have a number of women candidates and we have one gay candidate. And those candidates are going to have barriers if they win the nomination, or they win the general election, just like I did,” Obama told donors. “You can overcome that resistance if the way you are framing these issues and messages indicate, ‘Look, I’m part of an American tradition of opening up opportunity.’”

Obama also emphasized the need for candidates to think of appealing to America in a holistic sense, not just to one demographic.

“We should not be somehow thinking either we’re going for our base voter of young hipsters and African Americans and single women versus Joe lunch-pail, hard-hat guy,” he said. “Because you know what? I’ve had conversations with all those groups, and they share common dreams and common hopes and a vision for what a fair, just America would look like.”

The event occurred on Tuesday, the day before the fifth Democratic debate.

Obama used the debate stage to encourage unity among Democrats saying, “The truth of the matter is that every candidate on that stage believes we should provide” better health care and education and address climate change.