I think this may be nothing more than a potato plant. The flowers on potato plants grow these green tomato-type things and it is in the solanum family, as also are tomatoes. If you dig it up and find small potatoes under the earth, this will be diagnostic.
it is a member of the Solanum family but isn't a spud - it's Black Nightshade (Solanum nigrum). It is poisonous containing various alkaloids - the ripe berries are actually probably the least toxic bit - nastier when green. Any part if eaten will cause abdominal pain, headaches, vomitting, diarrhoea.
Its a fairly common garden weed.