title: pickle/joblib AttributeError: module '__main__' has no attribute 'thing' in pytest
body: <p>I have built a custom sklearn pipeline, as follows:</p>
  
  <pre><code>pipeline = make_pipeline(
      SelectColumnsTransfomer(features_to_use),
      ToDummiesTransformer('feature_0', prefix='feat_0', drop_first=True,  dtype=bool), # Dummify customer_type
      ToDummiesTransformer('feature_1', prefix='feat_1'), # Dummify the feature
      ToDummiesTransformer('feature_2', prefix='feat_2'), # Dummify 
      ToDummiesTransformer('feature_3', prefix='feat_3'), # Dummify
  )
  pipeline.fit(df)
  </code></pre>
  
  <p>The classes <code>SelectColumnsTransfomer</code> and <code>ToDummiesTransformer</code> are custom sklearn steps implementing <code>BaseEstimator</code> and <code>TransformerMixin</code>.
  To serialise this object I use </p>
  
  <pre><code>from sklearn.externals import joblib
  joblib.dump(pipeline, 'data_pipeline.joblib')
  </code></pre>
  
  <p>but when I do deserialise with</p>
  
  <pre><code>pipeline = joblib.load('data_pipeline.joblib') 
  </code></pre>
  
  <p>I get <code>AttributeError: module '__main__' has no attribute 'SelectColumnsTransfomer'</code>.</p>
  
  <p>I have read other similar questions and followed the instruction in this blogpost <a href="https://www.stefaanlippens.net/python-pickling-and-dealing-with-attributeerror-module-object-has-no-attribute-thing.html" rel="noreferrer">here</a>, but couldn't solve the issue. 
  I am copying pasting the classes, and importing them in the code. If i create a simplified version of this exercise, the whole thing works, the problem occurs because i am running some tests with pytest, and when i run pytest it seems it doesn't see my custom classes, in fact there is this other part of the error 
  <code>self = &lt;sklearn.externals.joblib.numpy_pickle.NumpyUnpickler object at 0x7f821508a588&gt;, module = '__main__', name = 'SelectColumnsTransfomer'</code> which is hinting me that the <code>NumpyUnpickler</code> doesn't see the <code>SelectColumnsTransfomer</code> even if in the test it is imported.</p>
  
  <p>My test code</p>
  
  <pre><code>import pytest
  from app.pipeline import * # the pipeline objects 
                            # SelectColumnsTransfomer and ToDummiesTransformer 
                            # are here!
  
  
  @pytest.fixture(scope="module")
  def clf():
      pipeline = joblib.load("persistence/data_pipeline.joblib")
      return clf
  
  def test_fake(clf):
      assert True
  </code></pre>