Pre-heat the oven to 400°. Place the scrubbed beets on a large piece of parchment paper, drizzle with olive oil, and season with some salt and pepper. Close the parchment paper tight by twisting the sides and place it on a small baking sheet. Bake for 40 minutes to an hour, until the beets are fork tender.
While the beets are roasting, make the pesto: Place all of the ingredients in a food processor and pulse several times. Then while the food processor is running, add the olive oil in a slow stream. I like to keep it on the lighter side with less oil, so you end up with a thicker pesto. You can add as much or as little oil as you like. Place it in a separate bowl, cover, and set aside until you're ready to serve. Clean out the food processor because you will be making the gnocchi here.
When the beets are done, allow them to cool slightly and then peel off the skin. If you are using organic beets, you do not have to remove all of the skin, but I like to get rid of the gritty parts. Place the beets into a food processor and pulse several times until you have a smooth puree.
Then add the salt, pepper, and flour (and egg if you are using). I like to add the flour a little at a time until I have achieved a doughy consistency. The dough should be soft but not too sticky. Keep adding flour until it is not so sticky; however, the goal is to use as little flour as possible to achieve this. I have found that sometimes I need less flour than what I have recommended, and sometimes I need more. A lot of it depends on outside factors such as humidity and temperature so there is no set rule here.
Bring a small pot of water to a boil. This will be used to test your gnocchi before making a full batch .
Pinch off a small piece and roll it lightly in flour. Drop it into the boiling water. When it starts to float (after about three to five minutes) cook it for 30 seconds more. Fish it out with a slotted spoon and allow it to cool slightly. If it fell apart in the pot or it is falling apart or melting after it is cooked, add more flour into the dough. If it was not right the first time, keep on testing until you have it right.
When you have it right, place a few pieces of parchment on a flat surface (to keep the beets from staining the counter) and divide the dough into four portions. Make sure the parchment covered surface is well floured, and roll each portion out into a snake that is about a ½-inch thick. Using a knife or a metal spatula, cut the dough into ¾-inch bites.
Lightly flour a baking sheet and move the gnocchi over to the tray when they are done. Let them dry for an hour or refrigerate them for up to one day.
Prepare a large pot of boiling water. Set up a colander over a bowl near the boiling water. When the water is boiling, drop about 10 gnocchi in at a time. When the gnocchi start to float (after about three to five minutes) let them bob for about 30 seconds more and then scoop them out and place them in the colander. Lightly drizzle olive oil over them so they do not stick together. Repeat this process until all of the gnocchi are cooked.
Divide the gnocchi equally into bowls. Place a good sized dollop of the pesto on top of the gnocchi. If your pesto is more on the oily side, you can drizzle it over the gnocchi. Serve immediately.