sixty-north / cosmic-ray

Mutation testing for Python
MIT License
556 stars 54 forks source link

Dump with filtered operators #539

Open jmafoster1 opened 1 year ago

jmafoster1 commented 1 year ago

Summary

Dumping a database with filtered operators gives AttributeError: 'NoneType' object has no attribute 'value' because skipped jobs have no test outcome.

Steps to reproduce

  1. Create file ROOT/mod.py with content
    def func():
    return 1233 + 1
  2. Create file ROOT/test_mod.py with content
    
    import unittest
    import mod

class Tests(unittest.TestCase): def test_func(self): self.assertEqual(mod.func(), 1234)

3. Create file `ROOT/tutorial.toml` with content

[cosmic-ray] module-path = "mod.py" timeout = 10.0 excluded-modules = [] test-command = "python -m unittest test_mod.py"

[cosmic-ray.distributor] name = "local"

[cosmic-ray.filters.operators-filter] exclude-operators = [ "core/NumberReplacer" ]

4. Run `cosmic-ray init tutorial.toml tutorial.sqlite`
5. Run `cr-filter-operators tutorial.sqlite tutorial.toml`
6. Run `cosmic-ray exec tutorial.toml tutorial.sqlite`
7. Run `cosmic-ray dump tutorial.sqlite`
8. Observe error

cosmic_ray/cli.py", line 192, in result_to_dict d["test_outcome"] = d["test_outcome"].value AttributeError: 'NoneType' object has no attribute 'value'


The problem comes about because the filtered jobs are skipped, so have no `test_outcome`. This could probably be fixed with a simple `if` statement in the line above to test whether `d["test_outcome"] is not None` before trying to access the value, although that might then pass the problem further down the line. 

A fix is not a particularly high priority for me, but I thought I'd report the issue, and would be happy to attempt a pull request if that's something you're interested in.