import os
import mylib
os.system('make all')


def test_squared():
    assert 16. == mylib.squared(4) 


def test_myfunction():
    assert 16. == mylib.myfunction(mylib.squared, 4) 


os.system('make clean')

import os

import pytest

@pytest.fixture
def setup(request):
    def teardown():
        print("Running make clean")
        os.system('make clean')
        print("Completed finaliser")
    request.addfinalizer(teardown)
    os.system('make clean')
    os.system('make all')


def test_squared(setup):
    import mylib
    assert 16. == mylib.squared(4) 


def test_myfunction(setup):
    import mylib
    assert 16. == mylib.myfunction(mylib.squared, 4) 


Use pytest fixture to deal with compilation
Use pytest fixture to deal with compilation

  import os
- import mylib
+ 
+ import pytest
+ 
+ @pytest.fixture
+ def setup(request):
+     def teardown():
+         print("Running make clean")
+         os.system('make clean')
+         print("Completed finaliser")
+     request.addfinalizer(teardown)
+     os.system('make clean')
- os.system('make all')
+     os.system('make all')
  
  
- def test_squared():
+ def test_squared(setup):
+     import mylib
      assert 16. == mylib.squared(4) 
  
  
- def test_myfunction():
+ def test_myfunction(setup):
+     import mylib
      assert 16. == mylib.myfunction(mylib.squared, 4) 
  
  
- os.system('make clean')
- 
Use pytest fixture to deal with compilation
## Code Before:
import os
import mylib
os.system('make all')


def test_squared():
    assert 16. == mylib.squared(4) 


def test_myfunction():
    assert 16. == mylib.myfunction(mylib.squared, 4) 


os.system('make clean')

## Instruction:
Use pytest fixture to deal with compilation
## Code After:
import os

import pytest

@pytest.fixture
def setup(request):
    def teardown():
        print("Running make clean")
        os.system('make clean')
        print("Completed finaliser")
    request.addfinalizer(teardown)
    os.system('make clean')
    os.system('make all')


def test_squared(setup):
    import mylib
    assert 16. == mylib.squared(4) 


def test_myfunction(setup):
    import mylib
    assert 16. == mylib.myfunction(mylib.squared, 4) 

