Background: Surgical services are preparing to scale up in areas affected by COVID-19. This study aimed to evaluate the association between preoperative SARS-CoV-2 testing and postoperative pulmonary complications in patients undergoing elective cancer surgery.Methods: This international cohort study included adult patients undergoing elective surgery for cancer in areas affected by SARS-CoV-2 up to 19 April 2020. Patients suspected of SARS-CoV-2 infection before operation were excluded. The primary outcome measure was postoperative pulmonary complications at 30 days after surgery. Preoperative testing strategies were adjusted for confounding using mixed-effects models.Results: Of 8784 patients (432 hospitals, 53 countries), 2303 patients (26.2 per cent) underwent preoperative testing: 1458 (16.6 per cent) had a swab test, 521 (5.9 per cent) CT only, and 324 (3.7 per cent) swab and CT. Pulmonary complications occurred in 3.9 per cent, whereas SARS-CoV-2 infection was confirmed in 2.6 per cent. After risk adjustment, having at least one negative preoperative nasopharyngeal swab test (adjusted odds ratio 0.68, 95 per cent confidence interval 0.68 to 0.98; P = 0.040) was associated with a lower rate of pulmonary complications. Swab testing was beneficial before major surgery and in areas with a high 14-day SARS-CoV-2 case notification rate, but not before minor surgery or in low-risk areas. To prevent one pulmonary complication, the number needed to swab test before major or minor surgery was 18 and 48 respectively in high-risk areas, and 73 and 387 in low-risk areas.Conclusion: Preoperative nasopharyngeal swab testing was beneficial before major surgery and in high SARS-CoV-2 risk areas. There was no proven benefit of swab testing before minor surgery in low-risk areas.