Hi Greenshoes, what you say about dress codes around the hotel is correct but when out and about it's worth bearing in mind that if you want to visit any of the religious sites eg the Great Mosque in Sousse (which is definitely worth a visit) then both men and women are expected to dress modestly. This usually means keeping knees and shoulders covered - even men will be turned away if dressed in shorts that are above the knee and or wearing vest tops. At the mosque in Kairrouan you could hire a djellabah for 1Dinar to shrug on over your clothes but in Sousse the door man simply handed out checked tablecloths for people to wear sarong style around their lower body and a second one to wear shawl style over shoulders exposed in vest tops - not a good look, especially on men!
When a regular visitor to Tunisia and out and about from the hotel I used to wear lightweight linen drawstring trousers and kaftan style tops or ankle length loose linen shift dresses, mainly from my own choice in the first instance as I have to be very careful about exposing my skin to the sun, plus a large cotton square or sarong for wearing around my shoulders when necessary and it turned out to be ideal but I was never there in the heat of the summer, always either April or October. I also found that a very thin cotton sarong or shawl was handy for covering your head if attracting too much attention - it results in instant respect and a hassle free walk through the medina. A good compromise would be to dress in shorts but carry a couple of lightweight cotton sarongs with you - they will fold up small in your bag and then can always be worn sarong style if you feel uncomfortable with any undue attention that you might be attracting.
Most Tunisian women do not wear the hijab or traditional Islamic dress but they do dress fairly conservatively - eg skirts to just below the knee and short sleeved rather than sleeveless tops. The younger women are often to be seen in quite tight jeans but I've never seen them exposing any cleavage or wearing shorts. I realise that it is over 5 years now since I was last in Tunisia and things might have changed but in my experience European women attract attention in the form of stares but not necessarily direct hassle just because they are European. On the whole, given that places like Sousse, Hammamet and Tunis are large cities rather than beach resorts, I think that it a good rule of thumb is to ask yourself 'Would I walk around my home town dressed like this?' And if you decide that your shorts are too short to wear on your own High Street or that you are exposing an amount of flesh that would attract attention at your local bus stop then you can guarantee that it will attract too much attention on the streets of Sousse too

I've been amazed to walk behind women in the medinas dressed in quite skimpy shorts and bikini tops who've taken exception to being whistled and hissed at - but if they dressed like that around my home town here in Scotland they'd probably have been mistaken for sex workers here too!
Beach wear on city streets is always open to misinterpretion and clothing that won't attract attention on a beach, can and does give a quite different impression on a city street whether in Tunisia or in Lisbon as a friend found to her cost. She got short shrift from me and the other friend we were with - we pointed out that she'd never have dressed the way she did for a day trip round London so why on earth did she think that it was appropriate for a days sightseeing in someone else's capital city? So I think that the short (excuse the pun!) answer is that beachwear away from the beach or poolside is not a good idea but reasonably modest dress with some optional additional 'coverage' that can whipped out as required is.
SM
PS Unless the skin on your inner thighs is like leather, take some trousers with you if you plan on riding a camel - the thought of the chafing that could other wise ensue is making me wince just sat typing this!