BERLIN (Reuters) - The best of Germany and its humanitarian treatment of refugees is on display alongside the worst of Germany and its bouts of ugly anti-foreigner racism in a riveting new film about the crisis that premieres on Thursday.

“Willkommen bei den Hartmanns” (Welcome at the Hartmanns) is both a comedy and tragedy featuring Germany’s top actors and taking an entertaining look at how ordinary Germans are coping with the arrival of a million refugees since mid-2015.

A retired school principal played by Senta Berger offers to help teach German at a refugee centre and ends up convincing her skeptical husband, a prominent doctor, to take in a refugee, a man from Nigeria, at their home in a posh Munich district.

The family is at first badly divided by her open-arms embrace of the refugee, played by Eric Cabongo of Belgium, but soon warms to the man with his delightfully broken German even though neighbors and right-wing racists later hold noisy candlelight vigils of protest outside their villa.

The tensions in the film mirror a nationwide soul-searching that Germans have gone through since Chancellor Angela Merkel threw open the gates in September 2015 to refugees fleeing war and turmoil in Syria, Iraq, Afghanistan and elsewhere.

At first, Germans cheered the arrival of refugees as they flooded into the country. But the mood turned colder after a series of high-profile assaults on women in Cologne and other cities on New Year’s Eve and several bungled militant attacks by refugees inspired by Islamic State. Merkel has been blamed and her conservative party has suffered bitter defeats in several regional elections.

“We Germans are still so inhibited about our own identity even though we’ve got a free, tolerant and great country,” Elyas M’Barek, a German heartthrob of Tunisian origin, says at one point in the film, urging his girlfriend to be proud of the country. “We’ve got to stand up and defend those values.”

The film portrays the whole gamut of refugees: from those eager to integrate and learn German to others clinging to their cultures, from groups of young men without compunctions to assault women in public to an arrested Islamic State militant.

Simon Verhoeven - the director of the film, which also stars Heiner Lauterbach, Florian David Fitz and Uwe Ochsenknecht - started work in the spring of 2015 just before the numbers of asylum-seekers soared and had to repeatedly rewrite his script.

“All of a sudden, people were debating only one subject around the dinner table,” Verhoeven told the A.Z. newspaper on Monday. “The divisions in every family reflected the society splits across Germany. It was a curse and blessing at once.”