For test discovery to work where a dependent module is optional, you end up needing to do something like what is done in http://hg.python.org/cpython/rev/15ddd683c321:
-crypt = support.import_module('crypt')
+def setUpModule():
+ # this import will raise unittest.SkipTest if _crypt doesn't exist,
+ # so it has to be done in setUpModule for test discovery to work
+ global crypt
+ crypt = support.import_module('crypt')
That's kind of ugly. It would be better if unittest recognized SkipTest at import time during test discovery

FTR there is already an alternative to setupmodule:
try:
import module
except ImportError:
module = None
@unittest.skipUnless(module, 'requires module')
class ModuleTests(unittest.TestCase):
pass
This idiom is more lines than support.import_module, but works for non-stdlib tests too, and is useful when you don’t want the whole file to be skipped if the module is missing (like in distutils’ test_sdist where zlib can be missing).

FWIW the difference between support.import_module and the try/except/skip is that usually the former is used when *all* the tests require the imported module, whereas the latter is used when only some of the tests requires it.

Without the proposed enhancement, you could also combine Éric's approach with the original patch by doing something like:
try:
support.import_module(module)
except SkipTest:
module = None
def setUpModule():
if module is None:
raise SkipTest()

I agree that raising SkipTest (or subclasses thereof, such as ResourceDenied) at module level should be supported. That would mean no changes would be needed in most of the should-be-skipped-but-fail-instead tests listed in issue 16748 to make test discovery play nicely, and in fact the changes to test_crypt could be mostly reverted.
Personally, I don't find either of the suggestions given as alternates to what I did in test_crypt to be particularly prettier, not that what I did is pretty either.