Preheat oven to 375 degrees. Butter the bottom and sides of a 9 x 13 inch baking dish.
Slice the potatoes evenly and very thinly, preferably using a mandolin. Set aside in a bowl filled with water.
In a large saucepan or skillet, melt the butter over medium heat. Add the onion and pinch of salt and cook for about 10 minutes, stirring frequently, until the onions are soft and translucent. Do not brown.
Add the flour and mix well until combined, stirring constantly. Cook for a couple of minutes to remove the raw flour taste.
Slowly add the milk and half and half, stirring constantly. Cook over medium-low heat for about 5-10 minutes until the roux thickens enough to coat the back of a spoon or rubber spatula.
Add half of the Gruyere and all of the Parmesan cheeses, along with the basil pesto. Stir until the cheeses are melted and the roux is smooth and very creamy. Season to taste with salt/pepper.
Dry the potato slices thoroughly and stack, accordion style in the prepared baking dish.
Pour the Cheesy Basil Roux over the potatoes in the baking dish. Using a rubber spatula, gently tamp the sauce into the sides of the dish to coax it through the potato layers. Smooth out the top.
Top with the remaining cheeses and a little more black pepper. Cover the dish with foil and bake for about 1 hour 15 minutes until a sharp knife easily pierces the potatoes.
Remove the foil and bake another 15 minutes until the top is golden brown and bubbly.