We derive upper bounds on the rate of transmission of classical information over quantum channels by block codes with a given blocklength and error probability, for both entanglement-assisted and unassisted codes, in terms of a unifying framework of quantum hypothesis testing with restricted measurements. Our bounds do not depend on any special property of the channel (such as memorylessness) and generalise both a classical converse of Polyanskiy, Poor, and Verd{u} as well as a quantum converse of Renner and Wang, and have a number of desirable properties. In particular our bound on entanglement-assisted codes is a semidefinite program and for memoryless channels its large blocklength limit is the well known formula for entanglement-assisted capacity due to Bennett, Shor, Smolin and Thapliyal.