running unittests \ integration tests in python
Question: I have a Django project with multiple apps. Each app has a set of unittests.
I'm using pytest as my test runner. We have gotten to a point that we want to
start writing integration tests. I was wondering if there is any way to keep
the naming convention and thus the auto discovery of pytest but still be able
(via flag maybe?) to run the different test types. The most intuitive solution
that comes to mind is some sort of decorator on test methods or even
`TestCase` classes (something like Category in JUnit).  
something like:

    
    
    @testtype('unittest')
    def test_my_test(self):
        # do some testing
    
    @testtype('integration')
    def test_my_integration_test(self):
        # do some integration testing
    

and then i could run the test like:

    
    
    py.test --type=integration
    py.test --type=unittest
    

Is there such a thing?  
If not, the only other solution i can think about is to add a django command
and "manually" build a testsuite and run it with pytest... I would prefer not
to use this option. Is there any other solution that can help me?  
Thanks


Answer: You can [mark test
functions](https://pytest.org/latest/example/markers.html#marking-test-
functions-and-selecting-them-for-a-run).

    
    
    import pytest
    
    @pytest.mark.unittest
    def test_my_test(self):
        # do some testing
    
    @pytest.mark.integration
    def test_my_integration_test(self):
        # do some integration testing
    

These custom markers must be
[registered](http://pytest.org/latest/example/markers.html#registering-
markers) in your pytest.ini file.

Then use the `-m` flag to run the marked tests

    
    
    py.test -v -m unittest
    

