These verses were revealed in relation to the battle of Badr (Tanwir al-Miqbas min Tafsir Ibn Abbas).
The battle took place as a consequence of the Quraysh’s constant hostility and aggression. Soon as the Muslims fled persecution and found safe haven in Madinah, the Quraysh were once again on to the Muslims. They demanded the Madinan leaders to either expel the Muslims or they will come and murder everyone. This occurred before the battle of Badr. This is not an isolated incident many similar incidents occurred. Read more about these incidents here: “Did Quraysh Persecute Muslims When They Fled To Madinah?”
47:31 And We will surely test you until We make evident those who strive among you [for the cause of Allah] and the patient, and We will test your affairs.
47:32 Indeed, those who disbelieved and averted [people] from the path of Allah and opposed the Messenger after guidance had become clear to them – never will they harm Allah at all, and He will render worthless their deeds.
47:34 Indeed, those who disbelieved and averted [people] from the path of Allah and then died while they were disbelievers – never will Allah forgive them.
47:35 So do not weaken and call for peace while you are superior; and Allah is with you and will never deprive you of [the reward of] your deeds.
47:31 – The discourse in this verse speaks of the Muslims who resided in Madinah, just after they had been exiled out of their homeland fleeing persecution. God says that HE will indeed test the believers, to see who will strive to uphold the commands that was revealed.
47:32 – Here we are told that those who forcefully barred people from believing in the message of Islam and went up against the Prophet (p), they will not harm God in the least. All their deeds will come to waste (Tanwir al-Miqbas min Tafsir Ibn Abbas).
47:34 – Here again, it is clear that the Quraysh forcefully made people not accept the religion of Islam or when one did believe, they were tormented to torture so much so that they would eventually will leave. God reminds them, if they continued doing this and died upon doing this injustice, they will never be forgiven (Tafsir al-Jalalayn and Tanwir al-Miqbas min Tafsir Ibn Abbas).
47:35 – When the Muslims fled persecution from Makkah and eventually resided in Madinah, they were a handful, a couple of hundred of Muslims at best. The Muslims were up against a huge army of the Quraish which were keen on eradicating Islam and Muslims. This is why they were exhorted not to beg for peace, especially when they were outnumbered. They were told to fight until one were to be victories. However, if the Muslims were exhorted not to ask for peace, this does not mean that the enemy couldn’t ask for peace. Other verses of the Quran which were revealed on the same occasion, the Muslims were told that if the enemy Quraysh were to ask for peace, then the Muslims must end their fighting:
“And if they incline to peace, then incline to it [also] and rely upon Allah. Indeed, it is He who is the Hearing, the Knowing.” – 8:61
The aim for the Muslims was peace at the end. The fighting occurred as a result of the hostilities and preventing Muslims from practising their religion freely. As the verses (47:32 – 34) showed – the war and aggression was started by the Quraysh. In relation to them forcefully barring men from believing in Islam and when one did believe in the religion, they were tormented to torture and eventually made to renounce their faith (Mawdudi).
Dr. Muhammad Asad:
“39 For the above rendering of shaqqu, see note 16 on 8:13. The “cutting oneself off” from the Apostle signifies, of course, a rejection of his message, and, in this particular context, a refusal to follow the Qur’anic call to fight in a just cause, i.e., in defence of the Faith or of freedom (see note 167 on 2:190).
40 I.e., even if the fortunes of war go against them, the consciousness of having fought in the cause, of truth and justice is bound to enhance the inner strength of the believers and, thus, to become a source of their future greatness: cf. 3:139.” 
Sayyid Abul Ala Maududi:
“41 Here, one should bear in mind the fact that when this discourse was revealed only a handful of the Muslims consisting of a couple of hundreds of the Muhajirin and Ansar living in the small town of Madinah were upholding the standard of Islam and they were not only faced by the powerful Quraish but also by the whole of pagan Arabia. Such were the conditions when they were exhorted ‘not to be faint-hearted and not to beg (the enemy) for peace”, but to make preparations for the decisive conflict. This does not mean that the Muslims should never negotiate for peace, but it means that in a state like this it is not right to initiate peace negotiations when it shows the Muslims’ weakness, for it will still further embolden the enemy. The Muslims should first establish their superiority in power and strength; then if they negotiate peace there will be no harm.” 
Don’t forget to follow Discover The Truth on Facebook and Twitter. PLEASE help spread the word by sharing our articles on your favourite social networks.
 The Message of The Quran translated and explained by Muhammad Asad, page 1073
 Sayyid Abul Ala Maududi – Tafhim al-Qur’an – The Meaning of the Qur’an http://www.englishtafsir.com/Quran/47/index.html#sdfootnote41sym