# SystemExit: 2 when running unittest.main() with invalid arguments

- **ID:** `python/unittest-main-argv-error`
- **Domain:** python
- **Category:** config_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

The command-line arguments passed to unittest.main() are invalid or unrecognized, causing the test runner to exit with an error.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 3.8 | active | — | — |
| 3.9 | active | — | — |

## Workarounds

1. **Check the arguments passed to unittest.main() and correct them.** (90% success)
   ```
   unittest.main(argv=['first-arg-is-ignored', 'test_module'])
   ```
2. **Use unittest.TestLoader and unittest.TextTestRunner to run tests programmatically instead.** (85% success)
   ```
   loader = unittest.TestLoader(); suite = loader.loadTestsFromModule(module); runner = unittest.TextTestRunner(); runner.run(suite)
   ```

## Dead Ends

- **Passing sys.argv directly without validation** — If sys.argv contains invalid flags, the error persists. (70% fail)
- **Using unittest.main(exit=False) to suppress exit** — This suppresses the exit but does not fix the argument error; tests may not run. (80% fail)
